Jump to content

[SOLVED] formatting EXIF date (just one line of code) - help please


anon36

Recommended Posts

I don't know PHP at all, but I am trying to edit just one line just in order to format the date. This is for the photo gallery on my website. The PHP script automatically gets the EXIF data from the jpeg files and displays it on each webpage.

 

The original line is:

  echo ('<li>Date and time: '.($result[subIFD][DateTimeOriginal] ? trim($result[subIFD][DateTimeOriginal]) : $error).'</li>');

This works correctly and shows the date the photo was taken on. But the format is "2007:10:23 12:53:58", and I want "23 Oct. 2007" or just "Oct. 2007".

 

I looked at the PHP documentation, and tried

  echo ('<li>Date: '.($result[subIFD][DateTimeOriginal] ? date("j M. Y", strtotime(trim($result[subIFD][DateTimeOriginal]))) : $error).'</li>');

but this gives 31 Dec. 1969. So I tried

  echo ('<li>Date: '.($result[subIFD][DateTimeOriginal] ? date("j M. Y", strtotime(trim(""+$result[subIFD][DateTimeOriginal]))) : $error).'</li>');

but this gives the present date.

 

Please can anyone help?

 

The gallery I am using is Minimal Gallery, http://minimalgallery.net/home. My site is hosted by freehostia.com, which uses PHP 5.

There is probably an easier way, but this will work:

<?php
$tdate=trim($result[subIFD][DateTimeOriginal]);
$splitRaw=split(" ", $tdate);
$splitDate = split(":", $splitRaw[0]);
$newRawDate = mktime(0,0,0,$splitDate[1],$splitDate[2],$splitDate[0]);
$newDate = date("j M. Y", $newRawDate);  //lookup date() to see other formatting options here
echo $newDate;

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.