I am using MySQL DATE_FORMAT function to grab the date in the format i need it in. as the following:
SELECT DATE_FORMAT(`dob`, '%m-%d-%Y' ) as dob FROM `tblUsersProfile` WHERE `user_id` = 1
But now i want to update the date from this format to the default mysql date format?
I know how to do this in php, but iam trying to change the format in MySQL. Anyone know?
MySQL uses yyyy-mm-dd format for storing a date value. This format is fixed and it is not possible to change it. For example, you may prefer to use mm-dd-yyyy format but you can't.
In a MySQL database, the DATE_FORMAT() function allows you to display date and time data in a changed format. This function takes two arguments. The first is the date/datetime to be reformatted; this can be a date/time/datetime/timestamp column or an expression returning a value in one of these data types.
Similarly, if you want to get records for past one month rolling, that is, last 30 days, then here's the SQL query for it. select * from orders where order_date>now() - interval 1 month; In the above query, we select rows after past 1 month interval.
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().
You want MySQL's STR_TO_DATE()
function:
UPDATE tblUsersProfile SET `dob` = STR_TO_DATE('1-2-2011', '%m-%d-%Y') WHERE user_id = 1;
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