convert date to Mysql date format php


I have this date format in my db

19th April 2013

I want to convert it to


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


Use PHP's date function

date("Y-m-d",strtotime("19th April 2013"));


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


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 <ul><li><a href="http://www.sqlfiddle.com/#!2/7281e/1" rel="nofollow">SQLFiddle Demo</a></li> </ul>


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']));


  • How do I time my XSLT execution times to millisecond accuracy?
  • PHP create range of dates
  • Converting mysql date from one format to another
  • strtotime() converts a non existing date to another date
  • Show a link in fpdf
  • Kentico Repeater HTML Properties showing with selected transformation
  • How to search a CSV file with php by checking if a date falls between 2 ranges
  • how to solve invalid conversion specifier warning in iphone app
  • abstracting over a collection
  • SAXReader not re-ecape characters
  • Jackson Parser: ignore deserializing for type mismatch
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • OpenGL ES texture problem, 4 duplicate columns and horizontal lines (Android)
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • Websockets service method fails during R startup
  • Do I've to free mysql result after storing it?
  • How can I estimate amount of memory left with calling System.gc()?
  • Traverse Array and Display in markup
  • bootstrap to use multiple ng-app
  • Transpose CSV data with awk (pivot transformation)
  • Comma separated Values
  • A cron job substitute?
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • SQL merge duplicate rows and join values that are different
  • Acquiring multiple attributes from .xml file in c#
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to set the response of a form post action to a iframe source?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Running Map reduces the dimensions of the matrices
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • java string with new operator and a literal
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?