Jump to content

Archived

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

jo.nova

HELP with date checker/adjuster

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

Share this post


Link to post
Share on other sites
[code]<?php
$somedate = "2006-08-30"; // for example
list($y,$m,$d) = explode("-",$somedate);
$threedayslater = date("Y-m-d", mktime(0,0,0,$m,$d+3,$y));
echo $somedate. " +3 days is ". $threedayslater;
?>[/code]

Share this post


Link to post
Share on other sites
[quote author=jo.nova link=topic=106249.msg424697#msg424697 date=1156947421]
How's it work? [/quote]

Magic!!

Share this post


Link to post
Share on other sites

×

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.