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 August 12th, 2003, 06:37 PM
john28uk john28uk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 13 john28uk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Adding Time

Hi

I Have this problem, I wish to add 7 hours to a time and date, the date and time are held in the following

PHP Code:
 $openusers = ("$todaysgamedate $gametime24hour"); 


This displays the date and time just how i need it, but I need to be able to add seven hours to the openusers value, how can i do this?

Many Thanks

John

Reply With Quote
  #2  
Old August 13th, 2003, 02:44 AM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 6
Try MySQL

A great way to do this sort of thing is via a MySQL call (assuming you have access to MySQL)

The following will add 7 hours to the current time and return the new date and time:

PHP Code:
 select date_format(date_add(NOW(), interval 7 hour),'%D %M %Y %T'


You would need to replace NOW() with the date and time you wanted to manipulate of course.

Take a look at http://www.mysql.com/doc/en/Date_an..._functions.html
for the full story.

Hope it helps.

Reply With Quote
  #3  
Old August 13th, 2003, 03:32 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
This is also simple to do in your application logic using:
PHP Code:
 $tstamp strtotime'+ 7 hours' );
/*---------------------------------------------------
Will return unix timestamp + 7 hours
----------------------------------------------------*/ 
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #4  
Old August 13th, 2003, 12:51 PM
john28uk john28uk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 13 john28uk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi

Thanks for those replies, but unfortunately it looks like I failed to explain myself properly,

The situation is that my site is hosted in a different time zone to where I live, and this is 7 hours different, so because my site has a simple cut-off time, after which site members cannot access a game I run I need this time to be the same as my time.

I do not want to mess with the any other parts of the code as it all works ok, but I need to change the value $openusers to be 7 hours ahead of the time and date in the vaules $todaysgamedate $gametime24hour.

Hope this explains it a little better

Many Thanks

John

Reply With Quote
  #5  
Old August 13th, 2003, 01:03 PM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 6
So what format are the date and time stored in, in the two variables $todaysgamedate and $gametime24hour?

Reply With Quote
  #6  
Old August 13th, 2003, 01:25 PM
john28uk john28uk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 13 john28uk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi

$todaysgamedate is stored like this 2003-08-14
$gametime24hour is stored like this 18:25:00

Thanks

John

Reply With Quote
  #7  
Old August 13th, 2003, 02:02 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
PHP Code:
/*--------------------------------------------
Your Defined Time
--------------------------------------------*/
$gametime24hour '18:25:00';
/*--------------------------------------------
Hours To Add
--------------------------------------------*/
$hours 7;
/*--------------------------------------------
Create New Timestamp
--------------------------------------------*/
$tstamp strtotime$gametime24hour '+ ' $hours ' hours' );
/*--------------------------------------------
Output New Time
--------------------------------------------*/
echo( date'h:m'$tstamp ) ); 

Reply With Quote
  #8  
Old August 13th, 2003, 02:10 PM
baines baines is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 33 baines User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 51 sec
Reputation Power: 6
or, just to complete the set

PHP Code:
 $sql="SELECT '$todaysgamedate $gametime24hour' + interval 7 hour";
$result=mysql_query($sql) or die(mysql_error());
$openusers=mysql_result($result,0); 


This will also cope with the date change if midnight is passed by the 7 hour increment.

Last edited by baines : August 13th, 2003 at 02:13 PM.

Reply With Quote
  #9  
Old August 13th, 2003, 04:41 PM
john28uk john28uk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 13 john28uk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for all the help guys

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Adding Time


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT