0

Hello,

I need to calculate dates, e.g: if i have this date on string "12-07-2008" and I want to add to this date 17 month.
How can I calculate this date.
are the a func that do this calculate ? or I nedd to write it ?

Thank you

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by diafol
0

There are plenty of datetime functions in PHP that may be useful to you. Here is a list of many of them, date_add and date_parse could both be useful to you depending on how you want to do it.

0

As darkagn says, there are loads of ways in which you could do it. You could use strtotime, keep everything within date functions or do a simple explode and mktime:

$bits = explode("-",$date);
$newdate = date('d-m-Y',mktime(0,0,0,intval($bits[1]) + 17,$bits[0],$bits[2]));

//this approach has the advantage of correctly dealing with overflows( month + 17).

Edited by diafol: n/a

0

ardav, thank you.

I used this code:

list($year,$month,$day) = explode("-",$row['prisonDate']);
$d = mktime(0,0,0,$month,$day,$year);
$dis = date("Y-m-d",strtotime("+".$discount ."months",$d));

And it's work fun

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.