homepage Welcome to WebmasterWorld Guest from 54.234.147.84
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Finding the date 36 hours ago
mktime seems to only get me 33 hours ago
pillsbur




msg:4088113
 10:46 pm on Feb 26, 2010 (gmt 0)

Hi,

I am trying to calculate the date and time 36 hours ago. Here is my code currently:

$thirtysixago = date('Y-m-d H:i:s', mktime(date("H")-36));
$now = date('Y-m-d H:i:s');
echo "Now: $now<br />";
echo "36 hours ago: $thirtysixago";

When I run this, I seem to get 33 hours ago, not 36. For instance, here's some recent output:

Now: 2010-02-26 17:43:05
36 hours ago: 2010-02-25 05:43:05

See? 33 hours ago.

I'd appreciate any help with this.

Thanks,
Glenn

 

Readie




msg:4088118
 10:53 pm on Feb 26, 2010 (gmt 0)

$year = date(Y);
$month = date(m);
$day = date(d);
$hour = date(H);
$minute = date(i);
$second = date(s);

if($hour >= 12) {
$p_hour = $hour - 12;
$p_day = $day - 1;
} else {
$p_hour = $hour + 12;
$p_day = $day - 2;
}

$p_datetime = $year . '-' . $month . '-' . $p_day . ' ' . $p_hour . ':' . $minute . ':' . $second;


Course - problem with that is you then have to factor in... what if it's the 1st day of the month? or that first day of the first month of the year?

And that didn't occur to me until after I'd posted :/

Readie




msg:4088152
 11:44 pm on Feb 26, 2010 (gmt 0)

On re-reading your post...

Now: 2010-02-26 17:43:05
36 hours ago: 2010-02-25 05:43:05

Is actually correct... 5 in the evening, 5 in the morning.

pillsbur




msg:4088165
 12:08 am on Feb 27, 2010 (gmt 0)

Argh. Of course it is. I was confusing myself with the 24-hour part.

Thanks for being a "second pair of eyes".

Glenn

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved