Reputation: 1039
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
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
Upvotes: 2