3

I need this:

12 November, 1997

to be reformatted to:

1997-11-12

for inclusion in MySQL database, but I'm struggling with the full month name, is this possible?

Thanks

Darren

Mike B
  • 31,886
  • 13
  • 87
  • 111
StudioTime
  • 22,603
  • 38
  • 120
  • 207
  • have you seen this post? not sure if it will help you http://stackoverflow.com/questions/2487921/php-convert-date-format-yyyy-mm-dd-dd-mm-yyyy-not-in-sql – rogerlsmith Nov 03 '11 at 16:53
  • Voted to close. There's bunches of date conversion questions with the php tag. – Mike B Nov 03 '11 at 16:54
  • @Mike B - I agree and I wrote the bloody question - I did search but not using the correct words apparently, seen the error and will now vote to close too. – StudioTime Nov 03 '11 at 18:20
  • @DarrenSweeney You won't find a perfect match for your question. But if you browse through the top 5 [php] and [date] questions by vote you'll find 90% over PHP's date/time functions and how they might be applied to your particular problem. – Mike B Nov 03 '11 at 18:35

5 Answers5

10
$tempDate = '2013-06-09';
$day = date('l', strtotime( $tempDate));// will gives you the week day name 
$month = date('jS F Y',strtotime($tempDate));// will format like date 9th June 2013
Jitendra Pawar
  • 1,285
  • 15
  • 27
mukesh kumar
  • 101
  • 1
  • 2
2
date("Y-m-d",strtotime("12 November, 1997"));

Returns 1997-11-12, exactly what you need :)

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
1

You can use DateTime::createFromFormat, if you have PHP >= 5.3

nickb
  • 59,313
  • 13
  • 108
  • 143
1

Hacky method:

$timestamp = strtotime('12 November, 1997');
$sql = "INSERT INTO table (datefield) VALUES (FROM_UNIXTIME($timestamp))";

Somewhat less hacky:

$timestamp = DateTime::CreateFromFormat('j F, Y', '12 November, 1997')->format('U');
$sql = "same as above";
Marc B
  • 356,200
  • 43
  • 426
  • 500
1

This should work for you:

date("Y-m-d", strtotime(12 November, 1997));
kidata
  • 165
  • 1
  • 2
  • 15