What I want here is that the record will check from the database and if it is existing within time it will return true, and if not will return false,
What i think the problem here is the moment(startDate, 'DD/MM/YYYY hh:mm').toDate() (12hrs) because as you can see in the database the record are (24hrs)
and the result from convert is Thu Apr 14 2022 05:43:00 GMT 0800 (Philippine Standard Time)
var { assignedTo, startDate, duration } = data
//The value of startDate is `14/04/2022 07:11 PM`
var dd_startDate = moment(startDate, 'DD/MM/YYYY hh:mm').toDate()
var end = new Date(dd_startDate);
end = new Date(end.getTime(end.getTime() duration));
//dd_startDate = Thu Apr 14 2022 05:43:00 GMT 0800 (Philippine Standard Time)
//end = Thu Apr 14 2022 06:43:00 GMT 0800 (Philippine Standard Time)
var hasExisting = await _data.hasExistingEvent(dd_startDate, end);
hasExistingEvent: (startDate, end) => {
return new Promise((resolve, reject) => {
.....,("SELECT name FROM Event WHERE startDate BETWEEN '" moment(startDate).format() "' AND '" moment(end).format() "'", 100, function(data){
console.log("====RESULT====: ", data)
return resolve(data.length ==0)
})
})
},
this are the data from the database
CodePudding user response:
i guess you use the wrong date formatter
https://momentjs.com/docs/#/parsing/string-format/
try
('DD/MM/YYYY HH:mm')
From moments.js documentation
Input | Example | Description |
---|---|---|
H HH | 0..23 | Hours (24 hour time) |
h hh | 1..12 | Hours (12 hour time used with a A.) |
CodePudding user response:
Update hh with HH like this:
moment(startDate, 'DD/MM/YYYY HH:mm').toDate()
// parsed as hours (12) local time