Articles in this section

Calculate the number of days between dates

This article explains how to use handlebars helpers to calculate the number of days between dates.

21*24*60*60 = 1814400 = seconds in 21 days.

timestamp:

{{timeStamp}}

date+offset:

{{dateAdd myDate 1814400000}} //dateAdd uses milliseconds 

timeStamp in seconds from epoch:

{{dateFormat 'X' timeStamp}}

myDate in seconds from epoch:

{{dateFormat 'X' myDate}}

myDate in seconds + 21 days:

{{add 1814400 (dateFormat 'X' myDate)}} 
 {{#compare (add 1814400 (dateFormat 'X' timeStamp)) ">" (dateFormat 'X' myDate)}}

21 days from now is greater than myDate

{{else}}

21 days from now is less than myDate

{{/compare}}
Was this article helpful?
0 out of 1 found this helpful

Comments

6 comments
Date Votes
  • Tom Santiago,

    I only found adding number of days to the original dates, Can you help in figure out how to compare two dates and the difference in days?

    0
  • 0
  • I’m receiving the error: “Missing Helper: dateAdd”

    0
  • Sorry, ellan reddy. Could you share the full statement for us to try to troubleshoot? 

    0
  • Stephen Brandt - Basically, I need to add 2 years to the 'Last Modified Date'. I did follow the above provided syntax, but running into issues. Can you please help me out here?

    0
  • ellan reddy, is the handlebars statement failing to calculate as intended, or are you getting a design-time or runtime error? Perhaps you could post a screen capture here or paste in the error message. 

    0

Please sign in to leave a comment.