note 89601 added to function.strftime
| From: | dapikk | Date: | Mon, 16 Mar 2009 10:21:33 +0000 |
| Subject: | note 89601 added to function.strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151985@lists.php.net to get a copy of this message | ||
I had a need to subtrackt an older time from current time to get the time between.
Example: If one has worked from 2009-03-16 11:33:54 to 2009-03-16 12:01:54 then he has worked X
hours,minutes and seconds. I tried to find that X. And so - one solution would be:
<?php
$start_date = strtotime("2009-03-16 11:33:54"); //start date from database -
date("Y-m-d H:i:s") made as UNIX timestamp
$end_date = strtotime("2009-03-16 12:01:54"); //end date from database - date("Y-m-d
H:i:s") made as UNIX timestamp
$ajavahe = $end_date - $start_date;
$time_between = gmstrftime('%Hh %Mm %Ss', $ajavahe); //gmstrftime() deals with different
timezones correctly. (If in example you would be situated in Estonia and you would use strftime()
you get wrong answer off by 2 hrs, because timezone is GMT+2 - with gmstrftime() comes right
answer.)
echo 'You have worked: '.$time_between;
?>
Hope that this one makes someones life easier :D
----
Server IP: 195.222.16.155
Probable Submitter: ::ffff:194.240.150.6
----
Manual Page -- http://www.php.net/manual/en/function.strftime.php
Edit -- https://master.php.net/note/edit/89601
Del: integrated -- https://master.php.net/note/delete/89601/integrated
Del: useless -- https://master.php.net/note/delete/89601/useless
Del: bad code -- https://master.php.net/note/delete/89601/bad+code
Del: spam -- https://master.php.net/note/delete/89601/spam
Del: non-english -- https://master.php.net/note/delete/89601/non-english
Del: in docs -- https://master.php.net/note/delete/89601/in+docs
Del: other reasons-- https://master.php.net/note/delete/89601
Reject -- https://master.php.net/note/reject/89601
Search -- https://master.php.net/manage/user-notes.php