By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Calculating tim - easy for you! =)

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <8c**************************@posting.google.com >, georgios zakitraxis wrote:
Hello out there in the jungle...
=)

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


My favorite function: strtotime

Check it out in the manual :)
--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #2

P: n/a
georgios zakitraxis wrote:
Can I do this with times also?? .... I tried the above example, wit %H%M but it does not work?


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.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #3

P: n/a
"georgios zakitraxis" <ef****@yahoo.de> wrote in message
news:8c**************************@posting.google.c om...
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........


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);
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.