  ff1324 Everybody Goes Home Premium join:2002-08-24 On Four Day
| Convert EXIF datetime to usable PHP string
Okay...I've been banging my head on the desk today. I'm sure there's an easier way so I submit this to the gurus around here.
I am fetching the EXIF property "DateTimeOriginal" and it returns 2006:03:10 17:48:48. PHP's function strtotime requires it to be in the form 2006-03-10 17:48:48. (Notice the change in the colons and dashes.)
Either that, or figure out how to convert it to say "March 10, 2006". -- The funny thing about firemen...night and day they're always firemen |
|
  rjackson Premium,Mod join:2002-04-02 Ringgold, GA clubs:
Host: SMC Networks Automotive VOIP Tech Chat ViaTalk Teleblend
| I don't know that there's an easier way, but if not I cobbled this together. It uses the PHP explode() function to break the EXIF string into an array split on the colons, and then reassemble it into the format strtotime() expects. The output produces "March 10, 2006" like you want. php code:<?
$exifString = "2006:03:10 17:48:48";
$exifPieces = explode(":", $exifString);
$newExifString = $exifPieces[0] . "-" . $exifPieces[1] . "-" . $exifPieces[2] . ":" . $exifPieces[3] . ":" . $exifPieces[4];
$exifTimestamp = strtotime($newExifString);
echo date('F j, Y', $exifTimestamp);
?>
|
|
  rjackson Premium,Mod join:2002-04-02 Ringgold, GA clubs:
Host: SMC Networks Automotive VOIP Tech Chat ViaTalk Teleblend
| reply to ff1324 Here it is functionalized. php code:<? function convertExifToTimestamp($exifString, $dateFormat) { $exifPieces = explode(":", $exifString); return date($dateFormat, strtotime($exifPieces[0] . "-" . $exifPieces[1] . "-" . $exifPieces[2] . ":" . $exifPieces[3] . ":" . $exifPieces[4])); } ?>
And you would use it like this:
<? echo convertExifToTimestamp("2006:03:10 17:48:48", "F j, Y"); // returns "March 10, 2006" ?> |
|
  ff1324 Everybody Goes Home Premium join:2002-08-24 On Four Day | This is why I come here...My train of thought didn't even go near that idea.
BIG THANKS to rjackson!!! -- The funny thing about firemen...night and day they're always firemen |
|
  rjackson Premium,Mod join:2002-04-02 Ringgold, GA clubs: | Anytime...glad it worked for you. |
|
  Mospaw The new has started Hawaiian Jellyfish join:2001-01-08 The Pacific
·Cox HSI
Host: Road Warriors, Not.. All Things Macintosh Automotive
| This takes a slightly different approach, but also works:
<? function convertExifToTimestamp($exifString, $dateFormat) { $exifPieces = explode(" ", $exifString); return date($dateFormat,strtotime(str_replace(":","-",$exifPieces[0])." ".$exifPieces[1])); }
echo convertExifToTimestamp('2006:03:10 17:48:48', "F j, Y"); // returns March 10, 2006 ?> -- Mospaw.com. -- |
|
  rjackson Premium,Mod join:2002-04-02 Ringgold, GA clubs: | That works, and is a little shorter too  |
|
  Mospaw The new has started Hawaiian Jellyfish join:2001-01-08 The Pacific | I specialize in shortness.  |
|