Is there any way to find the response time, when I have two dates?

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]
Parents Reply
  • Former Member
    +1 Former Member in reply to vibhavtrivedi

    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>

Children