Discussion:
date time problem
Jim Giner
2013-10-06 22:19:39 UTC
Permalink
I always hate dealing with date/time stuff in php - never get it even
close until an hour or two goes by....

anyway

I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04".

So - where is the hour value of '07' coming from?? And how do I get this
right?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Farzan Dalaee
2013-10-06 22:36:34 UTC
Permalink
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);

Best Regards
Farzan Dalaee
I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get this right?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-10-06 22:42:10 UTC
Permalink
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get this right?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in
GMT? However, I did try it, changing the 'time_left' calc to use
"gmdate". Now instead of a 7 for hours I have a 12.

exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38

The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Farzan Dalaee
2013-10-06 22:49:02 UTC
Permalink
Try this please

gmdate("H:i:s", $diff%86400)

Best Regards
Farzan Dalaee
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get this right?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in GMT? However, I did try it, changing the 'time_left' calc to use "gmdate". Now instead of a 7 for hours I have a 12.
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-10-06 22:59:02 UTC
Permalink
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get this right?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in GMT? However, I did try it, changing the 'time_left' calc to use "gmdate". Now instead of a 7 for hours I have a 12.
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Farzan Dalaee
2013-10-06 23:07:14 UTC
Permalink
Its so freaky

Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get this right?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in GMT? However, I did try it, changing the 'time_left' calc to use "gmdate". Now instead of a 7 for hours I have a 12.
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jonathan Sundquist
2013-10-06 23:11:56 UTC
Permalink
This should help you out
http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php
Post by Farzan Dalaee
Its so freaky
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
Post by Jim Giner
I always hate dealing with date/time stuff in php - never get it
even close until an hour or two goes by....
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get
this right?
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in
GMT? However, I did try it, changing the 'time_left' calc to use "gmdate".
Now instead of a 7 for hours I have a 12.
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2013-10-06 23:14:46 UTC
Permalink
Jim,

The date method takes in a timestamp (not seconds away).

You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..

Aziz
Post by Farzan Dalaee
Its so freaky
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
Post by Jim Giner
I always hate dealing with date/time stuff in php - never get it
even close until an hour or two goes by....
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get
this right?
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in
GMT? However, I did try it, changing the 'time_left' calc to use "gmdate".
Now instead of a 7 for hours I have a 12.
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-10-06 23:29:22 UTC
Permalink
Look at my code. The inputs are all timestamps so date should work, no?
My question why am i getting an hour value in this case?

jg
Post by Aziz Saleh
Jim,
The date method takes in a timestamp (not seconds away).
You have the seconds, you will need to manually convert those seconds to what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
Aziz
Post by Farzan Dalaee
Its so freaky
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get this right?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in GMT? However, I did try it, changing the 'time_left' calc to use "gmdate". Now instead of a 7 for hours I have a 12.
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2013-10-06 23:40:03 UTC
Permalink
The resulting subtraction is not a valid timestamp, but rather the
difference between the two timestamps in seconds . The resulting diff can
be 1 if the timestamps are 1 seconds apart. The
link<http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php>Jonathan
sent out contains functions that does the division for you with
results. Another link you can check out:

http://stackoverflow.com/a/9143387/1935500
Post by Jim Giner
Look at my code. The inputs are all timestamps so date should work, no?
My question why am i getting an hour value in this case?
jg
Jim,
The date method takes in a timestamp (not seconds away).
You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
Aziz
Post by Farzan Dalaee
Its so freaky
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
Post by Jim Giner
I always hate dealing with date/time stuff in php - never get it
even close until an hour or two goes by....
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get
this right?
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in
GMT? However, I did try it, changing the 'time_left' calc to use "gmdate".
Now instead of a 7 for hours I have a 12.
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-10-07 01:09:01 UTC
Permalink
Post by Aziz Saleh
The resulting subtraction is not a valid timestamp, but rather the
difference between the two timestamps in seconds . The resulting diff can
be 1 if the timestamps are 1 seconds apart. The
link<http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php>Jonathan
sent out contains functions that does the division for you with
http://stackoverflow.com/a/9143387/1935500
Post by Jim Giner
Look at my code. The inputs are all timestamps so date should work, no?
My question why am i getting an hour value in this case?
jg
Jim,
The date method takes in a timestamp (not seconds away).
You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
Aziz
Post by Farzan Dalaee
Its so freaky
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
Post by Jim Giner
I always hate dealing with date/time stuff in php - never get it
even close until an hour or two goes by....
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get
this right?
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in
GMT? However, I did try it, changing the 'time_left' calc to use "gmdate".
Now instead of a 7 for hours I have a 12.
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Good Point! I never looked at it that way. I guess the Date function
can't be relied on in that case. So now I'll have to calculate my time
in a mathematical way instead of letting Date translate it for me.

Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ashley Sheridan
2013-10-06 23:55:50 UTC
Permalink
Post by Aziz Saleh
Jim,
The date method takes in a timestamp (not seconds away).
You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
Aziz
Post by Farzan Dalaee
Its so freaky
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
Post by Jim Giner
I always hate dealing with date/time stuff in php - never get it
even close until an hour or two goes by....
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get
this right?
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in
GMT? However, I did try it, changing the 'time_left' calc to use "gmdate".
Now instead of a 7 for hours I have a 12.
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz, please try not to top post :)

It's true that the date() function takes in a timestamp as its argument,
but a timestamp is a number representing the number of seconds since
00:00:00 1st January 1970, so passing in a very small number of seconds
is perfectly valid.

The only thing that would account for the 7 hours difference is the time
zone, which would also be part of the timestamp.
http://en.wikipedia.org/wiki/Unix_time gives more details.

Thanks,
Ash
http://www.ashleysheridan.co.uk
Jim Giner
2013-10-07 01:10:56 UTC
Permalink
Post by Ashley Sheridan
Post by Aziz Saleh
Jim,
The date method takes in a timestamp (not seconds away).
You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
Aziz
Post by Farzan Dalaee
Its so freaky
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
Post by Jim Giner
I always hate dealing with date/time stuff in php - never get it
even close until an hour or two goes by....
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get
this right?
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in
GMT? However, I did try it, changing the 'time_left' calc to use "gmdate".
Now instead of a 7 for hours I have a 12.
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz, please try not to top post :)
It's true that the date() function takes in a timestamp as its argument,
but a timestamp is a number representing the number of seconds since
00:00:00 1st January 1970, so passing in a very small number of seconds
is perfectly valid.
The only thing that would account for the 7 hours difference is the time
zone, which would also be part of the timestamp.
http://en.wikipedia.org/wiki/Unix_time gives more details.
Thanks,
Ash
http://www.ashleysheridan.co.uk
Thanks Ash, but the previous (top) post explained my dilemma just as you
have done here. My attempt to use a function to avoid "doing the math"
has now been resolved. Guess I'll have to do it the old-fashioned way.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Romain CIACCAFAVA
2013-10-07 03:21:55 UTC
Permalink
An easier way to do that would be using the diff() method of a DateTime object on another.

Regards
Romain Ciaccafava
Post by Ashley Sheridan
Post by Aziz Saleh
Jim,
The date method takes in a timestamp (not seconds away).
You have the seconds, you will need to manually convert those seconds to
what you desire (minutes = seconds / 60), (hours = minutes / 60), etc..
Aziz
Post by Farzan Dalaee
Its so freaky
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Try this please
gmdate("H:i:s", $diff%86400)
Best Regards
Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
You should use gmdate() if you want to how many hours left to expire
$time_left = gmdate("H:i:s",$diff);
Best Regards
Farzan Dalaee
Post by Jim Giner
I always hate dealing with date/time stuff in php - never get it
even close until an hour or two goes by....
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
anyway
// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);
exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.
BUT time_left is 07:43:04 when it should be only "00:43:04".
So - where is the hour value of '07' coming from?? And how do I get
this right?
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thanks for the quick response, but why do I want to show the time in
GMT? However, I did try it, changing the 'time_left' calc to use "gmdate".
Now instead of a 7 for hours I have a 12.
Post by Jim Giner
Post by Farzan Dalaee
Post by Jim Giner
exp 07:34:52
curr 06:40:14
diff 3158
left is 12:52:38
The 52:38 is the correct value, but not the 12.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Doesn't work either.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz, please try not to top post :)
It's true that the date() function takes in a timestamp as its argument,
but a timestamp is a number representing the number of seconds since
00:00:00 1st January 1970, so passing in a very small number of seconds
is perfectly valid.
The only thing that would account for the 7 hours difference is the time
zone, which would also be part of the timestamp.
http://en.wikipedia.org/wiki/Unix_time gives more details.
Thanks,
Ash
http://www.ashleysheridan.co.uk
Thanks Ash, but the previous (top) post explained my dilemma just as you have done here. My attempt to use a function to avoid "doing the math" has now been resolved. Guess I'll have to do it the old-fashioned way.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-10-07 14:07:09 UTC
Permalink
Post by Romain CIACCAFAVA
An easier way to do that would be using the diff() method of a DateTime object on another.
Regards
Romain Ciaccafava
Romain - you were so right. A little less calculating to be done and I
got the result I wished. For anyone interested here's the function I'm
using to determine how much time there is until a cookie expires. The
cookie in question contains the expiration datetime that was used to
create a paired cookie.

function GetTimeLeft($applid)
{
if (isset($_COOKIE[$applid]))
{
if (isset($_COOKIE[$applid."expire"]))
{
$curr_time = new datetime();
$cookietime = $_COOKIE[$applid."expire"];
$exp_time = new datetime();
$exp_time->setTimeStamp($cookietime);
$diff = $curr_time->diff($exp_time);
$days = $diff->format("%d");
$days = ($days > 1) ? "$days days": ($days == 1) ?
"$days day" : '';
$hms = $diff->format("%h:%i:%s");
return "Time left: $days $hms";
}
else
return '?';
}
else
return '0';
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Continue reading on narkive:
Loading...