Re: correct date (cont.)

From: Date: Thu, 09 Aug 2001 17:26:04 +0000
Subject: Re: correct date (cont.)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-62023@lists.php.net to get a copy of this message
On Thu, Aug 09, 2001 at 01:08:33PM -0400, DrWebPat@aol.com wrote: > Oops..(Hit send prematurely.) > > $currentmonth = date("m"); > $currentday = date("d"); > $year = date("Y"); > $newmonth = $currentmonth + 3; > if ($newmonth > 12){ > $newmonth = $newmonth % 12; > $year = $currentyear + 1; > } > $3months = date("Y-m-d",mktime(0,0,0,$newmonth,$currentday,$year)); > > This should get me exactly 3 months later and also checks for if its a later > month (oct, nov, or dec) then it goes to the next year. How could I check to > see if the new date doesn't fall on Feb. 30th or whatever? If someone signs > up on the 31st of a month it'll never end on a month with 31 days. > > Thanks, > Pat > Nothing to worry about... PHP does it for you. You can try it you know... Just use: $currentmonth = 2; /* feb */ $currentday = 31; $year = 2001; /* eg */ The output will then be: 2001-03-03 Ain't that most excellent?!?! I should tell you though... that: $3months = date("Y-m-d",mktime(0,0,0,$newmonth,$currentday,$year)); doesn't work. Obv. you haven't tried it. It produces an error (and no date). Your variable name cannot begin with a number. ===== PHP Manual ===== A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' ===== ===== So I'd say: $threeMonths. -- * R&zE: -- »»»»»»»»»»»»»»»»»»»»»»»» -- Renze Munnik -- DataLink BV -- -- E: renze@datalink.nl -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- H: +31 23 5516190 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- -- http://www.datalink.nl -- ««««««««««««««««««««««««

« previous php.general (#62023) next »