Get pre-defined value and assign in another field [duplicate]

-3

Speak, I have the following problem:

I need to get a date value already set so 2017-06-30 (YEAR-MONTH-DAY) and play it in another countdown script with the following parameters:

year: 2017, month: 6, day: 30,

In other words, I need to take the YEAR, MONTH and DAY and play in those fields, plus a VIRGLE. This date is already scheduled for the end of the promotion of a product X and always in the same format.

    
asked by anonymous 30.05.2017 / 02:37

1 answer

0

Where will this date come from? Will it be a form where the user enters the date? If it is, in this case you do not even need to use jQuery, just insert a field of type date into the form, as shown below:

<form action="pagina.php" method="POST">
  <input type="date" name="data" id="data">
</form>

Note: Although in the field the date appears in DD / MM / YYYY format, when you receive the value entered in the field it will come in YYYY-MM-DD format. From there, it is enough to separate the values of the date with the function of explode of PHP:

$data = $_POST['data'];
$partes = explode("-", $data);
//      ANO            Mês              DIA
//    $partes[0]     $partes[1]      $partes[2]
$day = $partes[2];
$month = $partes[1];
$year = $partes[0];

Edit: How do you get that date? If it comes from the database, after storing it in a variable, you can pass it to the script and then break the date as you need it:

var data = "<?php echo $data; ?>";
var array = data.split("-");

var day = array[2];
var month = array[1];
var year = array[0];
    
30.05.2017 / 13:16