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 ??
You can still do it via query so you will not have any conversion on PHP side. Since the data type of the column is string, you need to convert it to a valid date using STR_TO_DATE.
SELECT DATE_FORMAT(STR_TO_DATE(columnname, '%D %M %Y'), '%Y-%m-%d') new_format FROM TableName following PHP code convert the date into desired format
$date = '19th April 2013' echo date('Y-m-d', strtotime($date)); and other formats are as follows
April 22, 2013 date("F d, Y",strtotime($myrow['date'])); Monday, April 22, 2013 date("l, F d, Y",strtotime($myrow['date'])); Apr 22, 2013 date("M d, Y",strtotime($myrow['date'])); 22 April 2013 date("d F Y",strtotime($myrow['date'])); 22 Apr 2013 date("d M Y",strtotime($myrow['date'])); Mon, 22 Apr 2013 date("D, d M Y",strtotime($myrow['date'])); Monday, the 22nd of April, 2013 date("l",strtotime($myrow['date'])) . ", the " . date("jS",strtotime($myrow['date'])) . " of " . date("F, Y",strtotime($myrow['date']));