Date format

Post Reply
cloudgp
Posts: 92
Joined: Sat Apr 20, 2013 9:51 am

Date format

Post by cloudgp »

Hi, is there any way to change the date format in galleries? Instead of 2013-05-03 it was like 3 weeks ago, yesterday, today, 1 year ago..?
Thx
admin
Site Admin
Posts: 38004
Joined: Wed Sep 10, 2008 11:43 am

Re: Date format

Post by admin »

Add at the top of your template

<?php

function ezDate($d) {
$ts = time() - strtotime(str_replace("-","/",$d));

if($ts>31536000) $val = round($ts/31536000,0).' year';
else if($ts>2419200) $val = round($ts/2419200,0).' month';
else if($ts>604800) $val = round($ts/604800,0).' week';
else if($ts>86400) $val = round($ts/86400,0).' day';
else if($ts>3600) $val = round($ts/3600,0).' hour';
else if($ts>60) $val = round($ts/60,0).' minute';
else $val = $ts.' second';

if($val>1) $val .= 's';
return $val;
}

?>

and do like this where you need that type of date

<?=ezDate('<!--ACTIVATION_DATETIME-->'); ?>
Don't forget to run script update
cloudgp
Posts: 92
Joined: Sat Apr 20, 2013 9:51 am

Re: Date format

Post by cloudgp »

Awesome! Thanks
admin
Site Admin
Posts: 38004
Joined: Wed Sep 10, 2008 11:43 am

Re: Date format

Post by admin »

NP
Don't forget to run script update
Brett
Posts: 31
Joined: Wed Dec 18, 2013 10:21 pm

Re: Date format

Post by Brett »

admin wrote:Add at the top of your template

<?php

function ezDate($d) {
$ts = time() - strtotime(str_replace("-","/",$d));

if($ts>31536000) $val = round($ts/31536000,0).' year';
else if($ts>2419200) $val = round($ts/2419200,0).' month';
else if($ts>604800) $val = round($ts/604800,0).' week';
else if($ts>86400) $val = round($ts/86400,0).' day';
else if($ts>3600) $val = round($ts/3600,0).' hour';
else if($ts>60) $val = round($ts/60,0).' minute';
else $val = $ts.' second';

if($val>1) $val .= 's';
return $val;
}

?>

and do like this where you need that type of date

<?=ezDate('<!--ACTIVATION_DATETIME-->'); ?>
I did this and nothing is displaying. Any idea what's wrong?
admin
Site Admin
Posts: 38004
Joined: Wed Sep 10, 2008 11:43 am

Re: Date format

Post by admin »

Nope, you have the entire code, add a few debug lines and so on.
Don't forget to run script update
Post Reply