cf_sql_timestamp vs cf_sql_date vs getdate()
If there's one thing I don't like it is people confusing a date with a timestamp, and how a lazy bit of development can ruin a load of data. Here is a simple query inserting data to a timestamp I found in a system where all the created dates were truncated because of the incorrect syntax.
Bad one which was in use:
insert into testdate values (<cfqueryparam cfsqltype="cf_sql_date" value="#createodbcdatetime(now())#">);
Result :
2015-09-29 00:00:00.000
Best One (easiest to read)
insert into testdate values(getdate() );
Result :
2015-09-29 10:10:09.880
Not great (no binding)
insert into testdate values(#createodbcdatetime(now())#);
Result :
2015-09-29 10:14:44.000
What the bad one should have been
insert into testdate values(<cfqueryparam cfsqltype="cf_sql_timestamp" value="#createodbcdatetime(now())#">)
Bad one which was in use:
insert into testdate values (<cfqueryparam cfsqltype="cf_sql_date" value="#createodbcdatetime(now())#">);
Result :
2015-09-29 00:00:00.000
Best One (easiest to read)
insert into testdate values(getdate() );
Result :
2015-09-29 10:10:09.880
Not great (no binding)
insert into testdate values(#createodbcdatetime(now())#);
Result :
2015-09-29 10:14:44.000
What the bad one should have been
insert into testdate values(<cfqueryparam cfsqltype="cf_sql_timestamp" value="#createodbcdatetime(now())#">)
Comments
Post a Comment