Jump to content

Decrement date


damo87

Recommended Posts

I am displaying a table of football matches, which includes columns for venue and date. The complete code is quite long, so I'll just show the relevant parts:

 

$query="SELECT venue, date_format(datetime, '%M %e, %Y, %l:%i%p') as newdate,.....

 

Then I define some variables from the query:

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
$datedisplay = $nt[newdate];

 

Then display the results in a table:

echo "<tr><td class=right>$nt[hometeamname] $homefinalscore</td>.......<td class=center>$nt[venue]</td><td>$datedisplay</td>.......</tr>";

 

So I get my date/time displayed in the table like this:

April 1, 2010, 7:40pm

 

This is all working fine. All the dates are stored on the database in a particular time zone, which is the same time zone as my server time, which makes it easy to do things such as restrict changing selections for a game that has already started. What I would like to change though, is to display the game date/time in the local time for that game location.  There are only two venues where the time zone is different, so I imagine I would need to do something like "if venue = S,  $datedisplay=$datedisplay-2" (if the venue 'S' is two hours behind the server time.)

 

Just to clarify, I am not looking to change the date displayed based on my users' location. Everyone, no matter their actual location should see the same game time displayed. Thanks in advance for any suggestions.

 

Link to comment
Share on other sites

Cant you save the timezone, change it to do what you want, fiddle about with the dates/times and then change it back?

 

date_default_timezone_set('GMT');

 

or whatever...?

 

I always write a mickey-mouse program to test stuff like this and then put it into the main program when it is working in the mickey-mouse program.

Link to comment
Share on other sites

Thanks for the response, ocpaul20. I'm not familiar with 'date_default_timezone_set' so Ill have to do my research to fully understand how it could help. In the mean time, I have simply created a new date/time column in the database So I have one datetime column that is used to display the date on the page (which shows the game in the local time of the game location), while the other datetime column (which is the server time of the game start time) which is used to do other stuff, such as lock down any further tipping once the game has started. I really have no idea about whether this is a better solution than manipulating the dates with php :shrug:. I suppose it is a better solution for me right now because it is the only way I know to get it to work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.