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
https://forums.phpfreaks.com/topic/19150-help-with-date-checkeradjuster/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.