I have created a variable,
var NovDate = new Date();
This date is in MON DD YYYY Format. I want to convert this to YYYMMDD format.
If I write the function : var NovDate = formatDate(NovDate, "%4Y%2M%2D%2H%2M%2S"); , I'm getting an error as below:
JST-310000 Error while compiling script 'WKF5041/start' line 6: NovDate.getDate is not a function.
Please assist.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @shri91127 ,
You are using the same variable name with the variable declaration format (means adding the var). Javascript has a feature called variable hoisting. This will move all variable declarations to the top of the scope. So when you call formatDate function, the data type of NovDate would be string. Try removing var from the line having formatDate function call.
Hi @shri91127 ,
You are using the same variable name with the variable declaration format (means adding the var). Javascript has a feature called variable hoisting. This will move all variable declarations to the top of the scope. So when you call formatDate function, the data type of NovDate would be string. Try removing var from the line having formatDate function call.
Hi @Krishnanunni ,
Thanks for your response.
I tried the below per your solution, I'm still getting the same error.
var NovDate = new Date();
NovDate = formatDate(NovDate, "%4Y%2M%2D%2H%2M%2S");
Is this how you meant earlier?
I'm not sure if this is the appropriate syntax:
formatDate(NovDate, "%4Y%2M%2D%2H%2M%2S")
This works with formatDate(new Date(), "%4Y%2M%2D%2H%2M%2S");
Thanks!
Views
Replies
Total Likes
@shri91127 ,
I have executed the following code and it gave me the right result, a NovDate string with the format shared.
var NovDate = new Date(); NovDate = formatDate(NovDate, "%4Y%2M%2D%2H%2N%2S"); logInfo(NovDate);
If you are getting error in JS activity, that could be due to error in other lines of code. Could you please try just these 3 lines of code in a separate JS activity and see if it works?
Views
Likes
Replies
Views
Likes
Replies