I wanted to find the reponse time between two days, the two dates are example blog.DateCreated and First comment date.
reponse time between two dates
[edited by: vibhavtrivedi at 8:09 AM (GMT 0) on Tue, Oct 5 2021]
I wanted to find the reponse time between two days, the two dates are example blog.DateCreated and First comment date.
Where are you wanting to do this comparison? In-process it would just be a matter of fetching the two dates and making the comparison. The best way to accomplish this in widget scripting would be to make a custom extension method to compare two dates and return the difference according to your specifications.
I wanted to do using widget script api, I have two datetime (eg : 30-09-2021 13:08:08) But I need to convert them into days format, so that I can substract both days, and get Reponse time in form No of days
Instead of doing this directly in Velocity, I recommend either making a custom extension method as described above, or using Server-side javascript (jsm file) to define an extension method to use in Velocity.
For example, add this file 'api.jsm' to the widget in question:
return { dateDiff: function(endDate, startDate) { // Calculate number of days between two dates return Math.floor((endDate - startDate) / (1000*60*60*24)); } };
Then reference it in your widget like so:
#set($api = $core_v2_widget.ExecuteFile('api.jsm')) <span> $api.dateDiff($firstCommentDate, $blogCreatedDate) days until first reply </span>
Thank you so much, It's Working
Thank you so much, It's Working
HTH! Note that if you want to use this in multiple widgets, you'll have to copy this to each one, whereas a custom extension would be available to all widgets automatically.