I've been facing a challenge for days now with DateTime values.
My API backend is built using entity framework and sql server in .netcore.
The main issue occurs when trying to send a datetime from Angular to the C# backend. I have observed that Date() in typescript/javascript automatically incorporates my timezone, which I am not sure how to exclude.
For instance, my date appears as follows: Wed Jul 11 2019 21:00:00 GMT+0300 But once it reaches c#, it transforms into 07/10/2010 (mm-dd-yyyy), subtracting one day due to the timezone difference.
Is there a method to standardize the Date variable to disregard timezone and consistently retain the format DD-MM-YYYY?
I attempted using MomentJS but still cannot resolve it; even the comparisons seem odd due to this problem.
As an example:
const VacationStart = moment(calendarEntity.Vacation.StartTime).utc(false);
const VacationEnd = moment(calendarEntity.Vacation.EndTime).utc(false);
if (VacationStart.isSameOrBefore(ColumnDate,'day') && VacationEnd.isSameOrAfter(ColumnDate,'day')) {
return '#FF0000';
}
In the provided instance:
VacationStart is Wed Jul 10 2019 21:00:00 GMT+0300
VacationEnd is Wed Jul 17 2019 00:00:00 GMT+0300
ColumnDate is Thu Aug 15 2019 03:00:00 GMT+0300 (incremental value)
Nevertheless, despite utilizing isSameOrBefore(ColumnDate,'day') to exclusively compare up to days, it does not function as intended. When VacationEnd should be equivalent to ColumnDate, it returns false.
Note: all of this is taking place within a foreach loop where ColumnDate increments by +1 day.