Re: Date Problem
| From: | George Whiffen | Date: | Wed, 21 Nov 2001 17:39:57 +0000 |
| Subject: | Re: Date Problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-75414@lists.php.net to get a copy of this message | ||
Mindhunter wrote:
>
> Hi,
>
> I am reading a date from an input in format 'DD-MM-YYYY' ex. 10-11-2001.
> Now I want to add 3 months to the date. I have tested mktime and strftime
> etc and no matter what I do I get the year as 1970. (Systemdate works
> fine). How would I go about adding 3 months to a date in that format?
>
> Thanks
> MH
The following works for me:
$mydate = '10-11-2001';
list($myday,$mymonth,$myyear) = explode('-',$mydate);
$mymktime = mktime(0,0,0,3 + $mymonth,$myday,$myyear);
$newdate = date('d-m-Y',$mymktime);
newdate is then 10-02-2002
You might check :
1. You always use a 4 digit year
2. mktime order of arguments i.e. hours,minutes,seconds,months,days,years
3. Output date format on date() function
4. There are problems with dates pre 1970 AND pre 1901, (pre 1970 is pre unixtime, pre 1901 is pre
phptime). I had problems with pre 1901 dates which the calendar module solved ( see jdtojulian,
juliantojd)