RE: Date Manipulation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As was already mentioned, mktime() and strtotime() both return a serial
date.  I use mktime() a lot to add/subtract days and such.  It
automatically compensates for leap days and all that.

Example:

<?php
$month = 1;
$day = 31;
$year = 2004;

$serialdate = mktime(0,0,0,$month,$day + 1,$year);

echo date("m/d/Y", $serialdate);
?>

This should output "2/1/2004" (unless I made a typo).

The initial 0,0,0 are the hour, minute, second.  It works equally well
with any numbers you give it for any of those values and if you throw it
back into the date() function, you can format the outputted date however
you want.


I know mktime and strtotime were already mentioned, but I think examples
help too so pardon me for expanding on it.

-TG

> -----Original Message-----
> From: Christopher Weaver [mailto:booktues@xxxxxxxxx] 
> Sent: Tuesday, November 30, 2004 9:19 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Date Manipulation
> 
> 
> I've looked at the date functions in the manual but can't 
> find what I need. 
> All I want to do is add and subtract days without ending up 
> with bogus date 
> values.  IOW, Nov. 29 + 7 days shouldn't be Nov. 36.
> 
> Just a nod in the write direction would be great.
> 
> Thanks. 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux