Welcome to WebmasterWorld Guest from 54.162.108.167

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

# Finding the date 36 hours ago

## mktime seems to only get me 33 hours ago

#### pillsbur

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

#### Junior Member

joined:Jan 26, 2006
posts: 41

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

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

#### Senior Member

joined:Dec 13, 2009
posts:945

``\$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 :/

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

#### Senior Member

joined:Dec 13, 2009
posts:945

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

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

#### Junior Member

joined:Jan 26, 2006
posts: 41

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

Thanks for being a "second pair of eyes".

Glenn