Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » Webmasters and Developers » Convert EXIF datetime to usable PHP string
Search Topic:
Uniqs:
540
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
Anyone using NSIS installer? »
« Paypal Alternative for ecommerce that has Customer Refferals  
AuthorAll Replies


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.
Forums » Tech and Talk » OS and Software » Webmasters and DevelopersAnyone using NSIS installer? »
« Paypal Alternative for ecommerce that has Customer Refferals  


Friday, 04-Dec 02:25:00 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 10 years online! © 1999-2009 dslreports.com.
page compression OFF
Most commented news this week
· [162] Comcast Releasing Promised Usage Meter
· [140] Avast Antivirus Has Gone Mad
· [104] Graduate Student Unveils Sprint's GPS Sharing With Feds
· [99] Comcast Makes NBC Universal Acquisition Official
· [85] Google Invades ISP, OpenDNS Turf With Google Public DNS
· [81] Latest Consumer Reports Survey Not Kind To AT&T
· [70] Baltimore To Ban Lazy Cable Installs
· [65] Sprint Defuses GPS Privacy Media Bomb
· [64] Broadband Killed The Game Console
· [58] FCC Ponders Moving From PSTN To IP Voice
Most people now reading
· False positive in Avast! or is it real? [Security]
· Heating - my dad gave me this advice... [Home Repair & Improvement]
· Maximizing Rogue DPS for ToC/ToGC (3.x) [World of Warcraft]
· Linux is terrorist - according to MS... [All Things Unix]
· [Business] how to bridge a smc 8014 business class modem [Comcast HSI]
· [WIN7] Outlook express under Windows 7? [Microsoft Help]
· [Rant] Disrespect of PTO [Rants, Raves, and Praise]
· [video] Electrical Wire Tears Apart Tree [56k Lookout (Broadband Heavy)]
· [TWC] Audio/Video outage in Brooklyn [Time Warner Cable TV/Voice]
· Connecting to Google Voice Via SIP [VOIP Tech Chat]