jo.nova Posted August 30, 2006 Share Posted August 30, 2006 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]<?phpif (($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 Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 30, 2006 Share Posted August 30, 2006 [code]<?php$somedate = "2006-08-30"; // for examplelist($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] Quote Link to comment Share on other sites More sharing options...
jo.nova Posted August 30, 2006 Author Share Posted August 30, 2006 Whoa...that's crazy. How's it work? ;) Thanks, I'll play with it!- Joe Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 30, 2006 Share Posted August 30, 2006 [quote author=jo.nova link=topic=106249.msg424697#msg424697 date=1156947421]How's it work? [/quote]Magic!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.