Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 08-10-2005, 10:31 AM   #1
Chop Chop
 
catacon's Avatar
 
Join Date: Jan 2005
Location: St. Louis, MO
Posts: 1,035
Send a message via AIM to catacon Send a message via Yahoo to catacon
Time Questions (PHP)

*Sigh*

I have been working on my website a lot lately and I have added somethings that have a timestamp on them (like a post in a forum). I want the members to be able to select which timezone they are in, and then have the script change the timestamp accordingly. So if I post at 3:00 PM (GMT -6) then in GMT -5 it would be 4:00 PM. How do take a date from a db and change it to the correct timezone depending on what the user has set?

Also, how would I set Daylight Savings Time? Like in this forum, you can select if you want DST, on, off, or automatically changed.

Any help would be much appreciated.
catacon is offline   Reply With Quote
Old 08-10-2005, 10:53 AM   #2
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
Be pretty easy to do. Just create a separate column in the database like time offset. You could then just subtract the value to give them their time.

DST would be more complicated. I would have to think on that one. You might download PHPBB and look at how they do some of their date calculations.
__________________

Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row
mairving is offline   Reply With Quote
Old 08-10-2005, 12:48 PM   #3
Chop Chop
 
catacon's Avatar
 
Join Date: Jan 2005
Location: St. Louis, MO
Posts: 1,035
Send a message via AIM to catacon Send a message via Yahoo to catacon
I would have to set the time to GMT first, before I add/substract the offset, right? I will get PHPBB and see what they do. Thanks!
catacon is offline   Reply With Quote
Old 08-17-2005, 07:05 PM   #4
Chop Chop
 
catacon's Avatar
 
Join Date: Jan 2005
Location: St. Louis, MO
Posts: 1,035
Send a message via AIM to catacon Send a message via Yahoo to catacon
PHPBB confused me, oh well. I am having a problem with taking time from the database.

Very simply, here is what I am doing.

PHP Code:

<?php


require_once ("includes/mysql_connect.php"); //connects to db

// Query only selects date/time, nothing else for now

$query "SELECT DATE_FORMAT(date_entered, '%M %d, %Y') AS de, HOUR(time_entered, '%H') AS he, MINUTE(time_entered, '%i') AS me FROM db LIMIT 5";

$result = @mysql_query($query);

if (
$result) {

   
$row mysql_fetch_array ($result);

   
$hour date 'g'$row['he'] );
   
$GMT $hour 6
   
$new_hour $GMT $_SESSION['time_offset'];
   
$minute date 'i'$row['me'] );
   
$ampm date 'A'$row['he'] );

   echo 
$new_hour:minute " on " $row['de'];

} else {
     echo 
mysql_error();
}

?>
The problem occurs when adding the time offset makes the time go into the next day. If I enter the Central 6:00PM that becomes GMT 12:00PM (noon, wrong) and then add the time_offset of 9 (for example) then it becomes 9:00PM the same day. It should be 7:00AM the following day (right?). And it prints it out as 21:00 PM too. Any help would be appreciated.

I am also still having trouble figuring out how to use DST.

Any typos in the code aren't in the code I am using, I just wrote this up fast to show what I was doing.

Thank you!

Last edited by catacon; 08-17-2005 at 07:13 PM.
catacon is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:55 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2