Can be set your way and call the event changeDate
To rescue the chosen value and format the new output, can be used a function another screen component ai gets the choice, example:
$(document).ready(function() {
$('#calendarioIni').datepicker({
format: 'dd/mm/yyyy',
startDate: '01/01/1998',
endDate: '31/12/1998',
language: 'pt-BR'
}).on('changeDate', function(e) {
$("#cid").val(e.date.toISOString().substring(0, 10));
console.log($("#cid").val());
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker3.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/locales/bootstrap-datepicker.pt-BR.min.js"></script>
<input type="text" id="calendarioIni" class="form-control" name="dataInicioCalendar">
<input type="hidden" id="cid" class="form-control" name="dataInicio">
In your case in particular what I did, create another field input type hidden
and the value chosen in the first input
will formatted for this input
, which can be rescued by PHP
and used in your query, example:
<?php
$dataNormal = $_POST['dataInicioCalendar']; // A DATA FORMATO BRAZIL
$data = $_POST['dataInicio']; // A DATA AQUI É FORMATADA yyyy-MM-dd
Reference: Documentación Oficial
See if dateFormat: "dd/mm/yyyy" helps you
– Zorkind
but the return is the same way @Zorkind
– V.Avancini
In onSelect: Function(selectedDate) {} you can format the return.
– Zorkind
@Zorkind could you exemplify for me? or send me some link with this explained? I’m new in the field
– V.Avancini
I think I understand what you want, when the form is posted you want the value to go in the yyyy-mm-dd format right? you can take the event of Submit and edit the value of the input before sending, understood?
– Zorkind
is exactly that @Zorkind , but I don’t know how to do that you said
– V.Avancini
is the bootstrap-datepicker? or what is the plugin?
– novic
@Zorkind, take a look here <?php if(isset($_POST['dataInicio']) && isset($_POST['dataFim']) { $dataIni = $_POST['dataInicio']; $dataFim = $_POST['dataFim']; $cod_orgao = $_POST['District']; $cod_drive = $_POST['County']; } ? > vc meant before sending me to trade?
– V.Avancini
@Virgilionovic boostrap even
– V.Avancini
in javascript, that.
– Zorkind
@V.Avancini do you want this answer via server? or in JAVASCRIPT? where do you want to use the final formatting?
– novic
"Return" you mean, send to the server?
– Sam
is the following, this date is used in a select SQL, I receive via html Post and stored in a variable in php, and I query via php passing the filled variable, understood?
– V.Avancini
But warning you here, it worked out what you did, but I need checaVazio for the user not send without the dates and make a wrong query
– V.Avancini
My answer gives you exactly what you want, in the form Submit, but you can do it in PHP too.
– Zorkind
All right. What was not clear to me, is: the guy selects the date, blz, appears in the field in the format dd/mm/yyyy... then you want to send this value to the server in the format yyyyyy/mm/dd in any variable that you use?
– Sam
@I use the date in a Select SQL and the date in the DBMS is in the format yyyy/mm/dd, so to do this I save the date value in a php variable and use it in the query I do, took?
– V.Avancini
I could understand no. So would the problem be php instead of JS? Sorry, your question is not clear. Vc posted a JS code and at the end it says "I would like for the user to appear in the format dd/mm/yyyy but to return in the format yyyy/mm/dd or even yyyy-mm-dd, as I could perform this procedure?".... It would be better to reformulate the question explaining exactly what you want, where the information comes from, where you go, how you want etc... I’ve read it 20 times and I couldn’t understand it
– Sam
is the following, I have the date field, I am using the bootstrap-datepicker to display the calendar, for the user to select the date, when he clicks on a date the field is filled, and I would like in the field the format is dd/mm/yyyy (Brazilian date standard)but with this date I do an SQL query, where my DBMS handles the date with the default yyyy/mm/dd, so I would like to save in a variable in this format to be able to perform my Select, now it was?
– V.Avancini
Now it’s better. I’m going to post an answer and see if that’s it.
– Sam