randytan
randytan

Reputation: 1039

Bootstrap Datetimepicker JS Format Date Output

i am using bootstrap-datetimepicker.min.js which originally from here (http://tarruda.github.io/bootstrap-datetimepicker/)

when i click some button, the ajax is returning datetime in this format:

Thu Jul 18 2019 07:00:00 GMT+0700 (SE Asia Standard Time)

how to make this format to yyyy-mm-dd so it can fit in mysql database?

i've see some function inside the js file there is formatDate(d) function. But there's no documentation regarding that function..

code for getting the result

  var expired_date= $('#dateTimeExpired').data('datetimepicker');
       exp_date = expired_date.getDate();

Is there any helps?

thanks in advance.

Upvotes: 1

Views: 2479

Answers (1)

Stan
Stan

Reputation: 26511

var dateRaw = "Thu Jul 18 2019 07:00:00 GMT+0700 (SE Asia Standard Time)";
var dateObject = new Date(dateRaw);
var dateFormatted = dateObject.toISOString().substring(0, 10);

alert(dateFormatted); // 2019-07-18

http://jsfiddle.net/eymA4/

Upvotes: 2

Related Questions