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

Recommended Answers

All 5 Replies

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.

Member Avatar for diafol

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).

Thank you :)

I found strtotime func

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

Member Avatar for diafol

OK, we solved? link below the edit box.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.