1

I am using the following bootstrap 3 datepicker.

http://eonasdan.github.io/bootstrap-datetimepicker/

it works fine but there is an issue . during the change event
the output thrown out is a js object. i want a string. is taht possible.

there is another question asked along the same lines. but current version of datepicker has been updated and the old code does not run in jsfiddle.

html code is as follows:

<div class="form-group">
   <div class='input-group date' id='datetimepicker5' data-date-format="YYYY/MM/DD">
      <input type='text' class="form-control" />
         <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
                </span>
            </div>
</div>

my jquery code is as follows ;

$(function () {
            $('#datetimepicker5').datetimepicker({
                pickTime: false,
                useCurrent: true,
                showToday: true,
                language : 'en'
            });
$('#datetimepicker5').data('DateTimePicker').show();
});


//.... on change event

$('#datetimepicker5').on('dp.change', function() {
var t3= $('#datetimepicker5').data("DateTimePicker").getDate();
alert (t3.format('YYYY-MM-DD)); // this is the new change and works perfect 
});

any help is really appreciated

pdp2907
  • 23
  • 2
  • 8
  • Awesome. this worked perfect. **bold** t3=$('#datetimepicker5').data('DateTimePicker').getDate(); alert(t3.format('YYYY-MM-DD')); – pdp2907 Jul 22 '14 at 12:59

1 Answers1

3

If I interpret the installation instruction correctly, Eonasdan already has moment.js as a dependency. This answer from a related question provides some sample code on using moment.js to format a date in JavaScript.

If for some reason moment.js is not available, you can fall back to the native JavaScript functions. See this answer from the same question as I previously referred to.

Community
  • 1
  • 1
Martijn
  • 5,491
  • 4
  • 33
  • 41
  • On StackOverflow, if the answer is correct, you should accept it by clicking the 'check' mark next to the answer. I would really appreciate it if you did this! – Martijn Jul 23 '14 at 19:14
  • done. thanx for pointing it out. i did not know it. regards .pdp2907 – pdp2907 Jul 25 '14 at 13:14