Jump to content

HELP with date checker/adjuster


jo.nova

Recommended Posts

I'm using the free DHTML date-chooser calendar from DHTMLgoodies.com.  I'm using it so that customers can simply pick a date from one interface instead of using three drop-down boxes.

The dates chosen from the calendar represent the date/time that a customer would like to pick up their project. So, to give us some time, I set the default due date to be three days from the current date:

[code]
<?php
$dateyear = date(Y);
$datemonth = date(m);
$dateday = date(d) + 3;
?>[/code]

But, if it were the 31st of August 2006, the above code would just set the due date to be the 34th of August 2006, which obviously is no good.

So, I wrote the following to compensate for this:

[code]
<?php
if (($datemonth == 01) & ($dateday > 31)) {$datemonth++; $dateday = $dateday - 31;}
if (($datemonth == 02) & (($dateyear % 4) == 0)){
if ($dateday > 29) {$datemonth++; $dateday = $dateday - 29;}
} else if (($datemonth == 02) & (($dateyear % 4) !== 0)) {
if ($dateday > 28) {$datemonth++; $dateday = $dateday - 28;}
}
if (($datemonth == 03) & ($dateday > 31)) {$datemonth++; $dateday = $dateday - 31;}
if (($datemonth == 04) & ($dateday > 30)) {$datemonth++; $dateday = $dateday - 30;}
if (($datemonth == 05) & ($dateday > 31)) {$datemonth++; $dateday = $dateday - 31;}
if (($datemonth == 06) & ($dateday > 30)) {$datemonth++; $dateday = $dateday - 30;}
if (($datemonth == 07) & ($dateday > 31)) {$datemonth++; $dateday = $dateday - 31;}
if (($datemonth == 08) & ($dateday > 31)) {$datemonth++; $dateday = $dateday - 31;}
if (($datemonth == 09) & ($dateday > 30)) {$datemonth++; $dateday = $dateday - 30;}
if (($datemonth == 10) & ($dateday > 31)) {$datemonth++; $dateday = $dateday - 31;}
if (($datemonth == 11) & ($dateday > 30)) {$datemonth++; $dateday = $dateday - 30;}
if (($datemonth == 12) & ($dateday > 31)) {$datemonth++; $dateday = $dateday - 31; $dateyear++;}
?>
[/code]

BUT, I'm still getting the same results: the date increases to a number that is beyond the number of days in a month. For exampe, I just ran the code and  the due date came up as August 33rd, 2006.

Where am I going wrong?

- Joe
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.