Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

CreateODBCDatetime tale of caution

I have a scedule task which runs daily and we've noticed that at the begining of the month it has been behaving oddly. Its been changing dates around. i.e its been converting 2006-08-03 to 2006-08-30. Below is an example of whats happend:

Before: {ts '2006-08-01 13:01:00'}   After: {ts '2006-08-10 00:00:00'}

view plain print about
1<cfset dateTest_after = createODBCDateTime(dateFormat(now(), 'yyyy-mm-dd')&'00:00:00') />
After spending considerable amount of time today thinking this was a CF bug and testing/re-testing my problem. I was stuck. The code worked fine for the other 27/28 days of the month. In the end I found out it was the lack of a space " " between date and time which caused this problem at the begining of the month. So it should read:
view plain print about
1<cfset dateTest_after = createODBCDateTime(dateFormat(now(), 'yyyy-mm-dd')&' 00:00:00') />

Painful its been, but a lesson to pass on

Comments Comments (5) | Print Print | Send Send | 1146 Views

Wouldn't createOdbcDate(now()) give you what you want?
Im setting the time to midnight as well though.
I know... doesn't createOdbcDate() default to 12:00 midnight? Or is that up to the DBMS?
I always just thought that was down to the DBMS and really didnt want to leave that to chance? Either way I suppose its better to be save than sorry :o)
cf datetimes are decimal days since it's epoch. this should strip the time: createODBCDATETIME(int(now())).
BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .