Search This Blog

Monday, October 8, 2007

DateDiff in coldfusion does not work the same way as dateDiff in sql

DateDiff in coldfusion does not work the same way as dateDiff in sql

I believe Coldfusion gets the different between date1 and date2 in ms and then converts this value to the date part that you specify on the dateDiff function. Sql subtracts the datepart value of date 1 from the date part value of date2.

What does that mean

DateDiff('d','2007/10/02','2007/12/01') in coldfusion is : 1 dateDiff(month,'2007/10/02','2007/12/01') in SQL is : 2 DateDiff('d','2007/10/02','2007/12/04') in coldfusion is : 2 dateDiff(month,'2007/10/02','2007/12/04') in SQL is : 2

To make coldfusion return the same value as SQL use this code

datePart('m',createDate(2007,12,1)) - datePart('m',createDate(2007,10,1))

No comments: