CodeIgniter Forums

Full Version: add dates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]chinedubond[/eluser]
hello please i need some help in adding dates.
I have this date lets say 12/12/09 i want to make it 13/12/10.i.e add i year to it .
how do i do that in php?

El Forum

[eluser]featureBlend[/eluser]
Dude its not that difficult:

Code:
<?php
    $futuredate = strtotime("365 days");
    echo date("F d, Y", $futuredate);
?>

My suggestion to you before you post queries here would be to give it a teeney weeney bit of research....GL with translating the date to your preferred output format.

El Forum

[eluser]chinedubond[/eluser]
Thanks for ur elp but i got a solution

$expiryDate= date("d-m-Y",mktime(0, 0, 0, date("d",$date), date("m",$date), date("Y",$date)+1));

El Forum

[eluser]obiron2[/eluser]
29/02/2008??

El Forum

[eluser]xwero[/eluser]
[quote author="chinedubond" date="1228143866"]Thanks for ur elp but i got a solution

$expiryDate= date("d-m-Y",mktime(0, 0, 0, date("d",$date), date("m",$date), date("Y",$date)+1));[/quote]
If your date is a unix timestamp just do
Code:
// constants.php
define('YEAR_IN_SECONDS',31556926);
// somewhere in your code
$expiryDate= date("d-m-Y",$date+YEAR_IN_SECONDS);
unix timestamps are just numbers so date calculations should be calculations instead of function calls.