DateAdd() Insanity...

by Rich Rousseau 24. March 2006 04:30

 

Not all DateAdd()s are created equal.

Example:

VBScript
DateAdd("m", -1, CDate("01/01/2006"))
Expected Result: 12/01/2005
Actual Result: 12/01/2006 - WTF?

TSQL
DateAdd(m, -1, '20060101')
Expected Result: 12/01/2005
Actual Result: 12/01/2005

Moral of the story, not all functions behave like you expect them to. Test, test and retest.