views:

40

answers:

2

At my company we store the information gathered from our site wide error template, into the database, but because of the format of the error.datetime it is making hard for me to do any sql queries for different date ranges.

Has anyone used some t-sql or coldfusion code to convert it to a mm/dd/yyyy format?

Here is an example of the format it currently is as.

Sun Jun 13 21:54:32 CDT 2010

But for any queries, I need to do, I have in a better format, I believe.

+2  A: 

On the CF side, you should be able to user createOdbcDateTime() to correctly format it for the database or dateformat() to format it as text. If the date is coming back as text instead of a date object, you could use parseDateTime() to convert to a date object.

Ben Doom
what if i wanted to do sorting by date in sql?
crosenblum
Use createOdbcDateTime(). This creates a SQL compatible datetime, which should insert into a datetime field without a probloem. Then, you can sort onthat column.
Ben Doom
+1 for `parseDateTime()`.
Ciaran Archer
A: 

As an alternative, you could avoid having to convert dates at all if you just use the SQL Server built-in getDate() function to fill out your date column as the error is being inserted into the database.

It may not be exactly the same time (i.e. it might be out by a ms or 10) but it should be pretty close and perhaps good enough for your purposes.

Just make sure that your database server and application server are time synchronised!

Ciaran Archer