简体   繁体   中英

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 !

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM