i have a date in this format
May 30 2006 12:00AM
is there a equivalent of strtotime() in mysql that will let me convert this to a mysql date?
mysql> select *from ConvertIntoDateFormat; The following is the output. The following is the query to format the date to YYYY-MM-DD. mysql> select str_to_date(LoginDate,'%d.
Change the curdate() (current date) format in MySQL The current date format is 'YYYY-mm-dd'. To change current date format, you can use date_format().
In MySQL, DATE_FORMAT function converts a DATE or DATETIME value to string using the specified format. In Oracle, you can use TO_CHAR function. Note that the DATE_FORMAT and TO_CHAR use different format strings.
MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' . The DATETIME type is used for values that contain both date and time parts.
I think you are looking for the STR_TO_DATE
function. Unfortunately, it is not quite as awesome as PHP's strtotime
, so you have to give it a format mask to parse:
mysql> SELECT STR_TO_DATE('04/31/2004', '%m/%d/%Y');
-> '2004-04-31'
For your date, I think the mask would be %M %e %Y %l:%i%p
, depending on whether or not you are expecting short/long month names and 0-based days. Based on your example it could be either:
mysql> SELECT STR_TO_DATE('May 30 2006 12:00AM', '%M %e %Y %l:%i%p');
+--------------------------------------------------------+
| STR_TO_DATE('May 30 2006 12:00AM', '%M %e %Y %l:%i%p') |
+--------------------------------------------------------+
| 2006-05-30 00:00:00 |
+--------------------------------------------------------+
1 row in set (0.00 sec)
Check out the full reference table for the mask options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With