Skip to main content
Inspiring
January 23, 2009
Question

Proper formatting for writing to the DateTime field in mySQL

  • January 23, 2009
  • 2 replies
  • 449 views
I need to timestamp or set particular dates which I will be writing to a datetime field in a mySQL database.

The format for that looks like this: 2009-01-23 01:01:01

I am able to write to the field by formatting like this: dateformat(Now(), "yyyy-mm-dd hh:mm:ss")

The problem is the "minutes" take on the "month" value (because I'm using the letter "m" in both places). Is there another letter other than "m" that I should be using for minutes? I have a reference book that says "n" but that didn't work. I'll attach the basic code below.
This topic has been closed for replies.

2 replies

Inspiring
January 23, 2009
Better yet, if mysql has a function that returns the current date and time, use it.
Inspiring
January 23, 2009
> writing to a datetime field

Then don't insert a string, insert a valid date/time object. The now() function returns a date/time object. Just add a cfqueryparam:

<cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">

> The problem is the "minutes" take on the "month" value (because I'm using the letter "m" in both places

If you check the documentation, DateFormat only handles the date portion. To format the time portion, you need to use TimeFormat.