-1

On click of bootstrap3 datepicker I am getting selected date and setting it as innerHTML to a table .

Below is my code

$('[id^="dp"]').datepicker({
        format: 'dd/mm/yyyy',
        autoclose: true
    }).on('changeDate', function (e) {
        // `e` here contains the extra attributes
        var Date = e.date;
        newDate=Date.(How to change format here ) 
        $(this).text(newDate);
 });

Currently e.Date giving me date in format

Tue Sep 05 2017 00:00:00 GMT+0530 (India Standard Time)

As per my knowledge its default format in jQuery .

How to change it in dd/mm/yyyy ??

Saurabh
  • 1,505
  • 6
  • 20
  • 37
Tanwer
  • 1,503
  • 8
  • 26
  • 41
  • Which datepicker plugin are you using? Why can't you just use `var date = $(this).val()`? – BenM Sep 08 '17 at 07:24
  • Are you trying to catch selected date in `dd/mm/yyyy` format? – Himanshu Upadhyay Sep 08 '17 at 07:26
  • @BenM I am using bootstrap3 datepicker – Tanwer Sep 08 '17 at 07:28
  • @HimanshuUpadhyay , I am trying to design editable row in html table , on click of table cell it will be editable and update new date by selecting new date from datepicker – Tanwer Sep 08 '17 at 07:29
  • @Jack, I am asking specifically about `changeDate`. What do you want to achieve on that event? I am asking because datepicker gives many options which you can use. So probably I can suggest you something. – Himanshu Upadhyay Sep 08 '17 at 07:36
  • @HimanshuUpadhyay , its ok Himanshu , other people got the problem . Thanks for your time – Tanwer Sep 08 '17 at 08:38

2 Answers2

2

You All ready getting everything in e.date

Seprate the month , day and year and than append them to get your desired format

var date = new Date(e.date),
    yr = date.getFullYear(),
    month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth(),
    day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
    newDate = day + '/' + month + '/' + yr;
Saurabh
  • 1,505
  • 6
  • 20
  • 37
1

You can use toLocaleDateString() to achieve this:

var test = new Date(Date.now()).toLocaleDateString();
alert(test);
DNKROZ
  • 2,634
  • 4
  • 25
  • 43