Jump to content

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


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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.