• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Proper formatting for writing to the DateTime field in mySQL

Contributor ,
Jan 23, 2009 Jan 23, 2009

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

375

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 23, 2009 Jan 23, 2009

Copy link to clipboard

Copied

> 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 23, 2009 Jan 23, 2009

Copy link to clipboard

Copied

LATEST
Better yet, if mysql has a function that returns the current date and time, use it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation