RE: [PHP] date maniplations
| From: | Boget, Chris | Date: | Wed, 14 Feb 2001 15:51:17 +0000 |
| Subject: | RE: [PHP] date maniplations | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-39648@lists.php.net to get a copy of this message | ||
> Sorry if I am confused by the date functions in the manual but I am.
> Here's what I want to do:
> I have a string in the form MM/DD/YYYY. I wish to:
> 1) convert it to a date
> 2) add $n days to it
> 3) convert back to a string in the same format above
> I believe I can accomplish [2] and [3] with:
> $mytdate = date("m/d/Y",mktime(0,0,0,date("m")
> ,date("d")+$n,date("Y")));
> How do I accomplish step 1?
> Can I type cast a string to a date?
No, but you can do this:
$startDate = explode( "/", $dateString );
$mytdate = date( "m/d/Y", mktime( 0, 0, 0, $startDate[0], $startDate[1]+$n,
$startDate[2] );
Chris