# Calculating tim - easy for you! =)

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hello out there in the jungle...
=)

I found out that i can calculate the dates e.g

\$today = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d"),
date("Y")));
\$yesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d") - 1,
date("Y")));
\$dayBeforeYesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"),
date("d") - 2, date("Y")));
\$dayBeforeTheDayBeforeYesterday = strftime('%Y%m%d',mktime(0, 0, 0,
date("m"), date("d") - 2, date("Y")));

and so on........

This works even if we have the 1st of August \$yesterday gives me the 31st
july.

Can I do this with times also??

e.g. Iit it now 17:06 an i want to make minus 20 min (like abopve minus 1
day) and I want the result to be 16:46.
I tried the above example, wit %H%M but it does not work?

Any ideas?

Thanks

:-X

## Re: Calculating tim - easy for you! =)

zakitraxis wrote:

My favorite function: strtotime

Check it out in the manual :)

--
Tim Van Wassenhove <http://home.mysth.be/~timvw

## Re: Calculating tim - easy for you! =)

georgios zakitraxis wrote:

....

Yes, it does :)

\$a_little_while_ago = strftime('%Y%m%d %H%M', mktime(date('H'),
date('i')-20, date('s'), date('m'), date('d'), date('y')));

--
USENET would be a better place if everybody read:   | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html   | my name in "To:" |
http://www.expita.com/nomime.html                    | no attachments.  |

## Re: Calculating tim - easy for you! =)

Unix timestamps are in general easier to work with as they're just numbers:

define(SECONDS_IN_A_DAY, 60 * 60 * 24);

\$now = time();
\$today = date("Y m d", \$now);
\$yesterday = date("Y m d", \$now - SECONDS_IN_A_DAY);
\$dayBeforeYesterday = date("Y m d", \$now - SECONDS_IN_A_DAY * 2);
\$dayBeforeTheDayBeforeYesterday = date("Y m d", \$now - SECONDS_IN_A_DAY *
3);