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,390
  • 13
  • 83
  • 110
StudioTime
  • 20,816
  • 34
  • 110
  • 202
  • 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,199
  • 14
  • 25
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
  • 311,322
  • 76
  • 447
  • 566
1

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

nickb
  • 58,150
  • 12
  • 100
  • 138
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
  • 348,685
  • 41
  • 398
  • 480
1

This should work for you:

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