Jump to content


Photo

HELP with date checker/adjuster


  • Please log in to reply
3 replies to this topic

#1 jo.nova

jo.nova
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 30 August 2006 - 02:05 PM

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:

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

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:

<?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++;}
?>

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 August 2006 - 02:09 PM

<?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;
?>

Legend has it that reading the manual never killed anyone.
My site

#3 jo.nova

jo.nova
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 30 August 2006 - 02:17 PM

Whoa...that's crazy.  How's it work?  ;)  Thanks, I'll play with it!

- Joe

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 August 2006 - 02:19 PM

How's it work?


Magic!!
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users