Skip to main content
added 112 characters in body
Source Link
Kermit
  • 34.1k
  • 13
  • 89
  • 121

The ANSI SQL standard format for date is YYYY-MM-DD HH:MM:SS. It's easier to capture the date in this format for insertion into a database.

In order to store the date with the format you're using (MM-DD-YYYY) you need to use the STR_TO_DATE function which allows you to convert a string to a date. The syntax for this function is:

STR_TO_DATE(str, format)

The specifiers for the format can be found here.

For your INSERT statement, you would use:

INSERT INTO `user` (`dob`) VALUES ( STR_TO_DATE('13-07-1990','%d-%m-%Y') ) 

The ANSI SQL standard format for date is YYYY-MM-DD HH:MM:SS. It's easier to capture the date in this format for insertion into a database.

In order to store the date with the format you're using (MM-DD-YYYY) you need to use the STR_TO_DATE function which allows you to convert a string to a date:

INSERT INTO `user` (`dob`) VALUES ( STR_TO_DATE('13-07-1990','%d-%m-%Y') ) 

The ANSI SQL standard format for date is YYYY-MM-DD HH:MM:SS. It's easier to capture the date in this format for insertion into a database.

In order to store the date with the format you're using (MM-DD-YYYY) you need to use the STR_TO_DATE function which allows you to convert a string to a date. The syntax for this function is:

STR_TO_DATE(str, format)

The specifiers for the format can be found here.

For your INSERT statement, you would use:

INSERT INTO `user` (`dob`) VALUES ( STR_TO_DATE('13-07-1990','%d-%m-%Y') ) 
Source Link
Kermit
  • 34.1k
  • 13
  • 89
  • 121

The ANSI SQL standard format for date is YYYY-MM-DD HH:MM:SS. It's easier to capture the date in this format for insertion into a database.

In order to store the date with the format you're using (MM-DD-YYYY) you need to use the STR_TO_DATE function which allows you to convert a string to a date:

INSERT INTO `user` (`dob`) VALUES ( STR_TO_DATE('13-07-1990','%d-%m-%Y') )