I register people online for a class and if they register before Day X, they get a discount. right now, I have to go in and manually change the code around on Day X by commenting out the earlybird code and un-commenting the regular code. Do you a suggestion for a way to get the code to check the date and change itself somehow? I think maybe PHP would be a way to check? I don't know alot about this stuff, just that there should be some way to do it.

3 answers

This was chosen as the best answer

I'd use PHP for this. Here's another example which checks if the current day is in the first or last three days of the month. If it is it can do one thing (show early bird rates), if it's not it can do something else (show regular rates).

$days_in_current_month = date('t'); // Days in current month
$current_day = date('j'); // Current day, as a number
$early_bird_start = '3'; // Number of days to allow at the start of the month
$early_bird_end = ($days_in_current_month - 3); // Number of days to allow at the end of the month
if (($current_day < $early_bird_start) OR ($current_day > $early_bird_end)) { // If the current day is in the first or last 3 days of the month 
    // Display the early bird pricing here
} else {  
    // Display the normal pricing here
Answered about 10 years ago by Edward Williams

The problem with any solution you're going to get is that everything done on a web page (either via JavaScript or some other way) is going to be a client-side operation. That's going to be an issue if someone is smart enough to figure out how to get around your coding on the web page and submit a class request using the early bird discount value (or any OTHER value, for that matter) regardless of the actual date.

In my opinion, it's better to do something like this on the server-side. That way you have complete control over what's submitted and whether it gets acted upon. It will require some effort on your part to learn a server-side language, such as PHP, ASP, etc., but it will also provide you with a little more security than relying upon JavaScript on the browser.

An example to do this in PHP would be something like:

$early_bird_date = "2000-09-01"; 
$todays_date = date("Y-m-d"); 

$today_unix = strtotime($todays_date); 
$early_bird_unix = strtotime($early_bird_date); 

if ($today_unix < $early_bird_unix) 
    // display the early bird pricing
    // display the normal pricing

(Please note that I'm not all that versed in PHP, so there may be a better way to do it than what I wrote above.)

Answered about 10 years ago by Michael Todd

Thanks guys. I'll try messing with the above.

Answered about 10 years ago by Rich Winter