|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
I am displaying a user's message from a guestbook, along with the time they sent the message. The only problem is the server time is four hours ahead. How might I go about subtracting four hours off the timestamp?
__________________
bow wow! |
|
#2
|
|||
|
|||
|
using gmtime??/
if u wanted to get the hours as a variable use this $hour =substr($time, 8, 2); //$hour = 14 something like that |
|
#3
|
|||
|
|||
|
Thanks for the help:
Here is the way the time is being stored on the db:
$guest_time = strftime("Posted time: %A, %B %d, %Y at %r." ,time()); How might I substrac four hours from this equation? I can change the timestanp if that is easier to manipulate. %r is the time from the server's clock. Thank you again. |
|
#4
|
|||
|
|||
|
To substract four hours from a timestamp you first need to know long four hours in a timestamp is. I don't have the number off the top of my head, but to find out use the mktime() function. Then take that minus your timestamp.
|
|
#5
|
|||
|
|||
|
A unix timestamp is just the amount of seconds since the unix epoch, and when you know 3600 is the amount of seconds in one hour, all you have to do is this: echo time() - 3600;
__________________
Best Regards, Håvard Lindset |
|
#6
|
|||
|
|||
|
Building on what Lindset is saying, you would modify your code to:
PHP Code:
|
|
#7
|
|||
|
|||
|
This was easier than I thought
I was unable to use use the string $newtime since each time I was getting a parst error, so I just did this:
$guest_time = strftime("Posted time: %A, %B %d, %Y at %r." ,time() - 14400); Thanks for your help, this worked fine. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > How could I subtract hours off a timestamp? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|