1

I'm creating a form with two date selectors. Currently, they look like:

<input type="date" class="form-control" name="contract_start" value="<?php echo $contract_start; ?>">

<input type="date" class="form-control" name="contract_end" value="<?php echo $contract_end; ?>">

Right now, on the form, the default values for the date selectors just say "mm/dd/yyyy". I'd like to know how I can alter this so that the contract_start input is the current date, and the contract_end input is 10 months from the current date by default. How can I do this?

  • 1
    important note: `input date` does not support `m/d/Y`, only `Y-m-d`, at least on chrome. [check](http://codepad.viper-7.com/2trH58) – Kevin Aug 20 '14 at 01:16
  • You are confusing placeholders with initial values. And if you mean just how to set initial (default) values relative to current date, you should show some effort in doing that and post the codee you have tried. – Jukka K. Korpela Aug 20 '14 at 05:58

2 Answers2

2

Just set $contract_end to:
date('m/d/Y', strtotime('+10 months', strtotime($contract_start)))

First strtotime call will convert raw date to timestamp, second will add ten months to your timestamp, and date function will format it back.

Strtotime reference
Date reference

baldrs
  • 1,869
  • 23
  • 28
0

You can use a single strtotime() function also in date function like this :

<?php

    $contract_start = date('Y-m-d');
    $contract_end   = date('Y-m-d', strtotime($contract_start.' +10 months'));

?>

<input type="date" class="form-control" name="contract_start" value="<?=$contract_start;?>">
<input type="date" class="form-control" name="contract_end" value="<?=$contract_end;?>">