Syed Atif
Syed Atif

Reputation: 19

how to add months to this date i get

$date = explode("/",$_POST['datum1']); // format is dd/mm/yyyy then use the below

$date_customer = $date[0];

let suppose i enter 4-1-2011, it will insert only 4 in the database by using insert query but now i want to add one month to it. mean if i enter 4th jan it inserts this, but wat wil be the code for inserting 4th Feb. date, 4th March and so on from the same input that is 4th jan ??

Upvotes: 0

Views: 2588

Answers (2)

vr_driver
vr_driver

Reputation: 2085

It'll probably work better like this:

$yourDate = "2012-10-05";
$mydate = date('Y-m-d', strtotime('+1 month', strtotime($yourDate)));

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382696

To add a month, you can use strtotime function something like this:

$mydate = date('Y-m-d', strtotime('+1 month', $yourDate));

Or you can use MySQL's ADDDATE function directly in your query like this:

ADDDATE(yourDateField, 1 Month)

Upvotes: 1

Related Questions