change date format

290 views
Skip to first unread message

Ian

unread,
Oct 23, 2019, 2:02:09 PM10/23/19
to bootstrap-datepicker
I have just started to use this datepicker and it works but after selecting a date, it adds it into the input field as yyyy-mm-dd and would prefer it if it was dd-mm-yyyy. I did try to alter the data-date-format="yyyy-mm-dd to data-date-format="dd-mm-yyyy" but it didn't store the date I selected in the database, it stored it as 0000-00-00

Below is the coding I currently have
<div id="exstdate" class="col-lg-6 input-group date" data-date-format="yyyy-mm-dd">
<input type="text" class="form-control" name="exstdate" value="<?php echo $exstdate; ?>" id="exstdate" readonly/>
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span><div class="error alert-danger"></div>
</div>

<script>
    $(function () {
  $("#exstdate").datepicker({
        language: 'en',
        autoclose: true, 
        todayHighlight: true,
        weekStart: 1,
        locale: 'en',
        dateFormat: 'dd-mm-yyyy'
  }).datepicker();
});
</script>

Is there any way to get the date selected in the input field as dd-mm-yyyy format instead of yyyy-mm-dd

Spas Bobchev

unread,
Oct 24, 2019, 2:43:42 AM10/24/19
to bootstrap-datepicker
What you describe seems more like an issue with your backend. Your database accepts dates with format yyyy-mm-dd but you're passing dd-mm-yyyy. The database server tries to create a date with the required format but fails and defaults to 0000-00-00. 
Reply all
Reply to author
Forward
0 new messages