0

Hi I am trying to manipulate date input from the user. I am accessing an api that requires a start date and end date, Currently I have the user entering the start date and the end date but I would ideally like the user to be able to input just the start date and the end date automatically assigned 7days later, I am currently using this code to assign the start and end date, Is it possible to just add 7days to the start date and assign that as the end date?

<div class="search-form">
<form action= "" method = "GET">
<div class="form-field">
<input type="type" name="start"  placeholder= "yyyy-mm-dd" value="<?php $startDate; ?>"/>


  </div>
  </form>
   <form action= "" method ="GET">
  <div class="form-field"> 
  <input type ="type" name= "end" placeholder="yyyy-mm-dd" value ="<?php $endDate;?>"/>

   </div>
    <button type="submit">Submit</button>


  </form>
</div>

2 Answers2

1

Please try this, e.g

$date = "Mar 03, 2011";
$date = strtotime($date);
$date = strtotime("+7 day", $date);
echo date('M d, Y', $date);

Hope it will help you.

Sanjay Chaudhari
  • 420
  • 4
  • 13
0
$date = "2016-08-24"
$startdate = date('Y-m-d', strtotime('+7 days',strtotime($date)));

You will get date after 7 days in YYYY-MM-DD format.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Kamlesh Gupta
  • 505
  • 3
  • 17