Jump to content

turn this string into dateformat


KingOfHeart

Recommended Posts

20091203192725

 

I only need to return the month and the day out of this string. I used substr to separate the data. How do I turn that output into date format.

Do I use a bunch of if statements, or do I use Date();?

I tried date but the output was wrong.

It returned something like this    January 06

and none of the dates are for January.

Link to comment
https://forums.phpfreaks.com/topic/184217-turn-this-string-into-dateformat/
Share on other sites

This will turn the date into the correct time (I assume it's 3rd December 2009 19:27:25 that the date should be)

$subject = '20091203192725';
$result = preg_replace('/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/s', '$1-$2-$3 $4:$5:$6', $subject);
$time = strtotime($result);

$time will then contain the date that you can use with the date function as you wish, such as

echo date('Y M', $time);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.