How can i save date in dd-mm-yyyy format in mysql and retrieve same format in php page ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

How can i save date in dd-mm-yyyy format in mysql and retrieve same format in php page ?

Php mysql date format issue

1st May 2020, 10:53 AM
Gaurav Dixit🇮🇳
Gaurav Dixit🇮🇳 - avatar
4 Answers
+ 4
Ishan Shah MySQL save data only YYYY-MM-DD FORMAT
15th May 2020, 7:25 AM
Gaurav Dixit🇮🇳
Gaurav Dixit🇮🇳 - avatar
+ 3
You can't save date in a different format and it's also not recommend. What you can do is modify the format while retrieving it. Check this : https://www.w3schools.com/sql/func_mysql_date_format.asp
4th May 2020, 12:13 PM
Amey Bhavsar
Amey Bhavsar - avatar
+ 2
You can try this: insert into DemoTable values(STR_TO_DATE('06-01-2019', '%m-%d-%Y')); For select statement: select *from DateFormatWithSelect where UserLoginDatetime order by str_to_date(UserLoginDatetime,'%d/%m/%Y') desc;
15th May 2020, 7:05 AM
Ishan Shah
Ishan Shah - avatar
0
insert into DemoTable values(STR_TO_DATE('06-01-2019', '%m-%d-%Y'));
16th May 2020, 8:16 AM
Avani Parmar
Avani Parmar - avatar