Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert date to Mysql date format php

Tags:

date

php

mysql

I have this date format in my db

19th April 2013

I want to convert it to

2013-04-19

I have used if,else conditions , BUt it becomes too long and complicated .Are there any built in functions ??

like image 380
Manoj K Avatar asked Feb 06 '26 20:02

Manoj K


2 Answers

Use PHP's date function

date("Y-m-d",strtotime("19th April 2013"));
like image 140
Yogesh Suthar Avatar answered Feb 08 '26 22:02

Yogesh Suthar


yes below code to change date format

date("Y-m-d",strtotime("19th April 2013")); to get as 2013-04-19

and for second one

    date("Y/m/d",strtotime("17th April 2013")); to get as 2013-04-17
like image 40
liyakat Avatar answered Feb 09 '26 00:02

liyakat