Jump to content

[SOLVED] mySQL question about default date format? Thank you!


bchandel

Recommended Posts

Is there any way to enter date in mySQL table directly in Month/Date/Year format automatically when a new record is added.

 

At present when I am adding data directly in the mysql table it does not enter date by itself. I have to type it in 0000-00-00 (Year-Month-Day) format

 

Is there any way to control this setting default properties for the date field in the table?

 

Thank you!

What I am looking is when you design table in MySQL is there any way to set date field in a way that any time you enter data the current date is added in the form of m-d-Y.

 

At present I have to enter the date in the record. I want this automatic process so when you create record date is entered in the date field in m-d-Y format.

 

I hope I am able to clarify. Thank you!

The YYYY-MM-DD format is not a "default" that can be changed, it is the format of a DATE data type. It exists for several reasons - it takes the minimum amount of storage, it has been optimized to result in the fastest queries, it can be directly sorted and used in greater-than/less-than comparisons, and a number of built-in mysql functions have been designed to use that format.

 

You must convert your date values into the YYYY-MM-DD format when you insert your data and convert the YYYY-MM-DD format back to your format when you retrieve the data. There are several ways to do this, but the quickest is to use the mysql built-in functions -

 

STR_TO_DATE(str,format) will allow you to put your date in as the str parameter (assuming you have validated that it is a correct date.)

 

DATE_FORMAT(date,format) will allow you to retrieve a standard DATE data type in any format that you want.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.