Re: [PHP] correct date (cont.)

2001-08-09 Thread Richard Lynch

> This should get me exactly 3 months later and also checks for if its a
later

No, it won't on leap years, or during daylight savings time changes, etc.

Don't try to do the year/month calculation yourself.

Let PHP do it for you, and it will be correct.  Every time.

$threemonths = mktim(0, 0, 0, date("m") + 3);

ACTUALLY, it would be even EASIER to use SQL to do this.  Presumably MySQL
will let you use things not unlike...

where registation_date + '3 months' <= now()

You're probably better off storing a registration_date and an interval than
the deadline.  Then, if you decide to extend everybody's 3 month freebie to
4 months, it's easy.

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] correct date (cont.)

2001-08-09 Thread Renze Munnik

On Thu, Aug 09, 2001 at 01:08:33PM -0400, [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
-- 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
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]