How to get the data of the startDate and endDate of the dateRangePicker?
This is my jquery below:
$(document).ready(()=>{
$('#daterange').daterangepicker({
opens: 'center',
showDropdowns : true,
startDate : moment().subtract(1,'day'),
endDate : moment().subtract(1,'day'),
locale :{
format: 'YYYY/MM/DD'
}
}), function(start, end, label){
window.alert("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
}
var yesterday = moment().subtract('day', 1);
console.log(yesterday);
});
I'm trying to get the data so i can input it on my d3.js chart. But when I console.log
the data of variable yesterday
it's returning
M {_isAMomentObject: true, _isUTC: false, _pf: {…}, _locale: P, _d: Sun Apr 19 2020 10:47:09 GMT+0800 (Philippine Standard Time), …}
_isAMomentObject: true
_isUTC: false
_pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -2, charsLeftOver: 0, …}
_locale: P {_calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", _dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/, ordinal: ƒ, …}
_d: Sun Apr 19 2020 10:47:09 GMT+0800 (Philippine Standard Time) {}
_isValid: true
__proto__: Object
I'm new to javascript and i thought it will show the same as the one in the daterangepicker:
You can achieve that with jQuery only:
$('#daterange').val()
There's no built-in way for that.
P.S.
chosenLabel
, which apparently was intended to be used with calling $('#daterange').data('daterangepicker').chosenLabel
, but it's always undefined.