General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 3rd, 2002, 11:15 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Post How could I subtract hours off a timestamp?

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!

Reply With Quote
  #2  
Old September 4th, 2002, 01:20 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
using gmtime??/

if u wanted to get the hours as a variable use this

$hour =substr($time, 8, 2);
//$hour = 14

something like that

Reply With Quote
  #3  
Old September 4th, 2002, 01:54 AM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
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.

Reply With Quote
  #4  
Old September 4th, 2002, 08:12 AM
Brian Rosner Brian Rosner is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Denver, CO
Posts: 34 Brian Rosner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to Brian Rosner Send a message via AIM to Brian Rosner Send a message via Yahoo to Brian Rosner
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.

Reply With Quote
  #5  
Old September 4th, 2002, 10:35 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to Lindset Send a message via AIM to Lindset
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

Reply With Quote
  #6  
Old September 4th, 2002, 03:49 PM
ejbe99 ejbe99 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 43 ejbe99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 40 sec
Reputation Power: 17
Building on what Lindset is saying, you would modify your code to:
PHP Code:
 $newtime time() - 14400;
$guest_time strftime("Posted time: %A, %B %d, %Y at %r." $newtime); 

Reply With Quote
  #7  
Old September 7th, 2002, 05:14 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > How could I subtract hours off a timestamp?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap