Sathish Chelladurai
Sathish Chelladurai

Reputation: 690

Difference between dateformat() and createODBCDate() in ColdFusion

What is the difference between dateformat() and createODBCDate() in ColdFusion? Are these two functions the same or not? When do I need to use DateFormat() and when do I need to use createODBCDate()?

Upvotes: 2

Views: 1267

Answers (1)

Scott Stroz
Scott Stroz

Reputation: 7519

dateFormat() accepts a date and a format 'mask' and returns a string of the date, in the format passed.

For example, consider the following code:

mydate = dateFormat( now(), 'yyyy-mm-dd' );

Assuming the date is July 15, 2014 (which it was when I wrote this) the value of the variable named 'mydate' would be '2014-07-15' (without the quotes). So, you need to pass a date to the function.

createODBCDate() creates an actual date from the values passed - it does not format the date, it merely creates a date 'object'

dateFormat() is typically used to display a date in a user friendly manner. Try running this writeDump( now() ) to see what the default display looks like.

createODBCDate() is typically used when you need to pass a date to a SQL query. However, if you use cfqueryparam with a cf_sql_type that accepts a date, ColdFusion will handle converting the value (assuming it is a valid date) to a date that the database accepts and you do not need to use createODBCdate()

In 10+ years of doing ColdFusion, I have never used createODBCDate()

Upvotes: 7

Related Questions