Trombone0904
Trombone0904

Reputation: 4268

save different date format into mysql

I have a datetime mysql column. I send an insert command with an date format:

YYYYMMDDTHHiiss

The date value was correctly stored as date time format of mysql. Is this the correct way or would it be best practice to send my date in format?:

YYYY-MM-DD HH:ii:ss

Thanks !

Upvotes: 0

Views: 84

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562681

Either is fine.

Read https://dev.mysql.com/doc/refman/8.0/en/date-and-time-literals.html

MySQL recognizes DATETIME and TIMESTAMP values in these formats:

  • As a string in either 'YYYY-MM-DD hh:mm:ss' or 'YY-MM-DD hh:mm:ss' format.

  • As a string with no delimiters in either 'YYYYMMDDhhmmss' or 'YYMMDDhhmmss' format, provided that the string makes sense as a date.

  • As a number in either YYYYMMDDhhmmss or YYMMDDhhmmss format, provided that the number makes sense as a date.

Upvotes: 1

Related Questions