0

Hi I'm still new in PHP and currently I want to make system about Employee Allowance and have no idea how to start calculate months in php .For example Steve should get allowance for 4 months from now and database stored the result of calculation, so far the coding is:

?php
$date=date_create("2013-03-15");
date_add($date,date_interval_create_from_date_string("40 days"));
echo date_format($date,"Y-m-d");
?>

Months input is from user and stored in database.

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
Mazrin
  • 9
  • 3

1 Answers1

0

I'm not sure I follow your 40 days versus 4 months, but I think you want something like this:

echo date('Y-m-d', strtotime("Now +40 days"));
Bing
  • 3,071
  • 6
  • 42
  • 81
  • it works , but currently i want **"Now +40 days"** is replaced by input by user. For example the input is **5** as integer . what else i can use besides 'strtotime' ? – Mazrin Jun 24 '15 at 01:17
  • `echo date("Y-m-d",monthAdd(id='period'));` – Mazrin Jun 24 '15 at 01:30
  • `strtotime` takes **almost any** human-readable form you can imagine. Here is a way to test it online: http://strtotime.onlinephpfunctions.com/ How is the user input being processed? POST, GET? Something like this would work fine: `echo date("Y-m-d", strtotime("Now +".$_POST['period']." days"))` – Bing Jun 24 '15 at 05:56