Tuesday, September 8

getdate() Without Time

I am rewriting the front end of a site, but can't change the back end or functionality. And so I must learn how to use an MSSql db via php. My first impression... they are not friends. Okay, moving on.

Problem:
Table has a datetime field, but the backend freaks out because of some 10yr old stored procedure. We traced it down to that the datetime can't contain the time.

Solution:
Now, I could have just used php date, but the day I found out that databases can insert their own date, I swore I'd never use it again for a current timestamp. So instead, my insert statement has this completely inelegent line:

convert(varchar(8), getdate(), 112)
That inserts the date with no time. Or more specifically, the time is 12:00AM. The actual contents is something like Sep 08 2009 12:00AM.

No comments: