Andy Jarrett // Code. Develop. Create.

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'}
  
    <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:


  <cfset dateTest_after = createODBCDateTime(dateFormat(now(), 'yyyy-mm-dd')&' 00:00:00') />

Painful its been, but a lesson to pass on

I’m here, learning and working away. If you liked this content and want to keep me going, consider buying me a coffee. Your support keeps this site running and the coffee brewing! ☕️