Wednesday, November 13, 2013

Find the difference between 2 dates in days in coldfusion

This is a requirement which is faced in our day to day coding life.  The  DateDiff() function is used.

Let me give an example.
 
     There's a scenario in which the last login date/time is compared against today's date/time. If the difference is more than 7 days, we send an e-mail alert to the user saying the user has not done any activity in the site.

LastLoginDate: 2013/10/01 20:10:10

noOfDays = DateDiff("d",DateFormat(LastLoginDate, "mm/dd/yyyy"),DateFormat(now(), "mm/dd/yyyy"));

noOfDays = 12.

This one did the work for me :)

No comments:

Post a Comment