Skipjackrick Posted February 25, 2010 Share Posted February 25, 2010 I've got a script that outputs the date and time as: 1998:03:20 00:10:00 I want to break apart that format into something like this <?php $month = 03; //get the month from the formatted date above $day = 20; //get the day from the formatted date above $year = 1998; //get the year from the formatted date above echo "You took that picture on $month / $day / $year"; ?> How do I do that? Link to comment https://forums.phpfreaks.com/topic/193369-date-format-help/ Share on other sites More sharing options...
aebstract Posted February 25, 2010 Share Posted February 25, 2010 Are you able to alter your sql query? Best way to do it would be to convert it from datetime to date when you retrieve your database information. If this isn't an option, we could easily take it and run a little code to pull the values out of the string. Just let me know which way you would rather do it. Link to comment https://forums.phpfreaks.com/topic/193369-date-format-help/#findComment-1018096 Share on other sites More sharing options...
Skipjackrick Posted February 25, 2010 Author Share Posted February 25, 2010 Are you able to alter your sql query? Best way to do it would be to convert it from datetime to date when you retrieve your database information. If this isn't an option, we could easily take it and run a little code to pull the values out of the string. Just let me know which way you would rather do it. I can't alter that format. It comes from the camera exif data. However, I can do this... <?php $date = '1998:03:20 00:10:00'; $dateval = strtotime($date); //this will output "890377200" ?> Link to comment https://forums.phpfreaks.com/topic/193369-date-format-help/#findComment-1018102 Share on other sites More sharing options...
aebstract Posted February 25, 2010 Share Posted February 25, 2010 This will give you your three values by themselves: $date = '1998:03:20 00:10:00'; $date = explode(" ", $date); $date = explode(":", $date[0]); echo "$date[0] $date[1] $date[2]" Link to comment https://forums.phpfreaks.com/topic/193369-date-format-help/#findComment-1018103 Share on other sites More sharing options...
Skipjackrick Posted February 25, 2010 Author Share Posted February 25, 2010 Thanks for the help! Works awesome Link to comment https://forums.phpfreaks.com/topic/193369-date-format-help/#findComment-1018181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.