2

I have been trying to change the datepicker's format from the default to yy-mm-dd but it isn't taking effect. I will add my code below for further reference. Thanks

HTML:

<input type="text" id="datepicker" name="call_date" class="form-control">

And the javascript is below:

JAVASCRIPT:

<script type="text/javascript">
    $(function() {
    $( "#datepicker" ).datepicker({dateFormat: 'yy-mm-dd');
    });
</script>

The dateFormat seems right but somehow it isn't taking effect and my database is getting inserted with zeroes, i.e 0000-00-00. Any help would be much appreciated. Thanks

EDIT: INSERTION QUERY

$date = $_POST['call_date'];
$logqry = "INSERT INTO clinic_log(log_date,log_time,log_caller,log_reason,log_response)VALUES('$date','$time','$caller','$reason','$response')";

$logresult = mysqli_query($conn,$logqry);
DEV
  • 647
  • 4
  • 19
  • 31

1 Answers1

3

your dateformat isn't applied beacuse you missed closing bracket '}' in the date format block,so the format is still the default one i.e. dd/mm/yy, like you mentioned in comment.

change this datepicker({dateFormat: 'yy-mm-dd'); to this datepicker({dateFormat: 'yy-mm-dd'});

here is the Working Fiddle after putting barcket.

JAVASCRIPT :

<script type="text/javascript">
    $(function() {
    $( "#datepicker" ).datepicker({dateFormat: 'yy-mm-dd'});
    });
</script>
Manoj Salvi
  • 2,639
  • 1
  • 17
  • 21
  • `` Hi, Manoj, Thanks for the answer but it still isn't working the date still shows as `08/12/2015` – DEV Dec 08 '15 at 08:43
  • i have given the fiddle , check when you pick the date from datepicker what format it takes in your code???? – Manoj Salvi Dec 08 '15 at 09:05
  • 1
    I got it working, i changed the format in the default function in the bootstrap-datepicker.js file `format: 'yyyy-mm-dd',` That was the line, it was set to `dd/mm/yyyy` Thanks a lot for all the help guys – DEV Dec 08 '15 at 09:12