Alex Rivera | Logout

How do I get next month date from today's date and insert it in my database?

Asked 2010-11-30T21:43:42.037
35

I have two columns in my db: start_date and end_date, which are both DATE types. My code is updating the dates as follows:

$today_date = date("Y-m-d");
$end_date = date("Y-m-d"); // date +1 month ??

$sql1 = "UPDATE `users` SET `start_date` = '".$today_date."', `end_date` = '".$end_date."'  WHERE `users`.`id` ='".$id."' LIMIT 1 ;";

What is the best way to make $end_date equal to $start_date + one month? For example, 2000-10-01 would become 2000-11-01.

Edit
Report

1 Answer

1

You can use strtotime() as in Gazler's example, which is great for this case.

If you need more complicated control use mktime().

$end_date = mktime(date("H"), date("i"), date("s"), date("n") + 1, date("j"), date("Y"));
answered 2010-11-30T21:47:18.230

Your Answer