/    Sign up×
Community /Pin to ProfileBookmark

Ajax call passes wrong Date

In a asp.net core application I have following code:

“`
$(‘.DepartmentDelete’).click(function (event) {
var r = confirm(‘Warning you are about to delete a record!’);
if (r === true) {
var id = $(this).attr(‘data-Id’);
var Depid = $(this).attr(‘data-DepId’);

var theDatestr = $(this).attr(‘data-datum’);
console.log(‘theDatestr: ‘ + theDatestr);
var datum = parseDate(theDatestr);
console.log(‘ datum: ‘ + datum);

$.ajax({
type: “post”,
url: ‘/RoosterMember/SetDepartment?handler=Delete’,
contentType: “application/json; charset=utf-8”,
dataType: “json”,
beforeSend: function (xhr) {
xhr.setRequestHeader(“X-XSRF-TOKEN”,
$(‘input:hidden[name=”__RequestVerificationToken”]’).val());
},
data: JSON.stringify({
UserId: id,
DepartmentId: Depid,
StartDate: datum
})
}).done(function (message) {
alert(message);
window.location.reload(true);
});
}
});
“`

When I run this I get following in my console window:

“`
theDatestr: 30-11-2021
datum: Tue Nov 30 2021 00:00:00 GMT+0100 (Central European Standard Time)
“`

But then when I look into the Network window I see:
StartDate: “2021-11-**29**T23:00:00.000Z”

so one day is subtracted from the Date!!
(with any date I use it subtracts always one day)
Also the receiving serverside routine is receiving this false date.

I am banging my head against the wall what I am doing wrong, especially because I am using this same routine on several slight different occasions without problems.

to post a comment

2 Comments(s)

Copy linkTweet thisAlerts:
@tracknutNov 29.2021 — Is this just an issue of comparing the date on your client to the date on the server which happens to be in a different time zone?
Copy linkTweet thisAlerts:
@NogDogNov 29.2021 — > @CodeRob#1639968 so one day is subtracted from the Date!!

> @tracknut#1639979 Is this just an issue of comparing the date on your client to the date on the server which happens to be in a different time zone?


Yep, looks that way, as it's the same time. The "Network window" value is at UTC (GMT), as indicated by the "Z" at the end, which is the same as the "console window" time at "GMT+0100".
×

Success!

Help @CodeRob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...