Time - dependent PHP code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jafil21
Forum Newbie
Posts: 13
Joined: Sun Oct 11, 2009 5:14 am

Time - dependent PHP code

Post by Jafil21 »

Hello everybody, I'm a PHP newbie and have the following situation:

I'm preparing a site for a night club in my city and want to provide the user with the option to book his seat online. For this procedure, I'm going to have to write a simple HTML form connected with a PHP script on my server, which will be doing INSERTs 99% of the time. However, in order to avoid last-minute confusion, I would like to freeze reservations that are submitted too late, for example, three hours or sooner before doors open. If that particular time of the day (i.e: the time when I want to freeze reservations) is 8pm (20:00) and my timezone is GMT + 2, then how am I supposed to code this condition in my PHP?

All that is needed is that an informative message be printed on the user's viewport, stating the inability to book seats as late as he or she attempted to.

Thank you for your time.

Note: I mentioned my time zone because the server I'm hosting my PHP script on is American (Texas, I believe), and the club is Greek. We're talking about diametrically opposed timezones.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Time - dependent PHP code

Post by Eric! »

Here's an example for converting to other timezones.

Code: Select all

date_default_timezone_set('Europe/Malta');
$today = date("D M j G:i:s T Y");
echo "<br />".$today."<br />";
Here's a list of supported Timezone strings in Europe:
http://us3.php.net/manual/en/timezones.europe.php

You can build your time string with date() function http://www.php.net/manual/en/function.date.php
with your selected timezone in whatever format your database is in, then compare the time strings in your query for valid time ranges for your reservations.
Post Reply