39

I am using bootstrap-datetimepicker plugin from Jonathan Peterson on my project.

I'm having a problem with change event :

If I define event like this :

$('#Release').on('dp.change', function(e){ console.log(e.date()); })

I get the error :

Uncaught TypeError: e.date is not a function

Anyone knows how to get new date value on change event ?

user5198552
  • 531
  • 1
  • 4
  • 7

3 Answers3

86

Looking at that link, it appears you are very close. You need to remove the parenthesis to get the right value.The way you currently are trying to log the value makes the browser think it needs to call a function.

$('#Release').on('dp.change', function(e){ console.log(e.date); })
Kenneth Salomon
  • 1,352
  • 11
  • 18
  • Reference: [https://eonasdan.github.io/bootstrap-datetimepicker/Events/#dpchange](https://eonasdan.github.io/bootstrap-datetimepicker/Events/#dpchange) – Nick Tsai Dec 19 '17 at 02:32
  • See an example here https://sourcecodezoneseven.blogspot.com/2019/06/bootstrap-datetimepicker-events-example.html – CodeDezk Jun 17 '19 at 12:16
16

Please use this code to get change event of datetimepicker:

 $('.datepicker').datetimepicker(
    { format: 'MM/DD/YYYY' }).on('dp.change', function (e) {  });
GhostCat
  • 137,827
  • 25
  • 176
  • 248
13

Thanks to Kenneth suggestion, I figured out :

$('#Release').on('dp.change', function(e){ 
    var formatedValue = e.date.format(e.date._f);
    console.log(formatedValue);
})

Thank you Kenneth :)

user5198552
  • 531
  • 1
  • 4
  • 7