Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL DATE_FORMAT reverse?

Tags:

mysql

pdo

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?

like image 480
M. of CA Avatar asked Aug 06 '11 22:08

M. of CA


People also ask

How do I change date format from YYYY-MM-DD in MySQL?

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.

Can we change the date format in MySQL?

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.

How do I get previous month records in MySQL?

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.

How do I change the format in MySQL?

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().


1 Answers

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;
like image 119
Michael Berkowski Avatar answered Sep 26 '22 00:09

Michael Berkowski