My SPA application is based out of Knockout as front end and ASP.Net Web API with EF as backend. Seems everything works fine until if someone changes submits date from India region. Though front end is correctly sending data to the web service, it seems
on the server side previous day is taken only if users are submitting any dates from India region. This is not an issue with any other region like US Central. There is no explicit conversion method used. I am scratching head and wondering who/what is going
on here. The field in question is declared as DateTime field. Any help would be much appreciated.
Thanks.
Regards,
Raj
Remember to click Mark as Answer on the post that helps to others.
As far as I think,you try to trust the client passing dates to the server as little as possible. For example, if you need "now", don't create a date on the client and then pass it to the server.
Either create a date in your GET and pass it or on POST do DateTime.UtcNow.
Or,you could pass dates and timezone to the server.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Participant
1042 Points
658 Posts
DateTime - Previous Day Issue for specific regions
Nov 11, 2020 02:02 PM|krisrajz|LINK
My SPA application is based out of Knockout as front end and ASP.Net Web API with EF as backend. Seems everything works fine until if someone changes submits date from India region. Though front end is correctly sending data to the web service, it seems on the server side previous day is taken only if users are submitting any dates from India region. This is not an issue with any other region like US Central. There is no explicit conversion method used. I am scratching head and wondering who/what is going on here. The field in question is declared as DateTime field. Any help would be much appreciated.
Thanks.
Raj
Remember to click Mark as Answer on the post that helps to others.
Contributor
3730 Points
1431 Posts
Re: DateTime - Previous Day Issue for specific regions
Nov 12, 2020 06:08 AM|yij sun|LINK
Hi krisrajz,
As far as I think,you try to trust the client passing dates to the server as little as possible. For example, if you need "now", don't create a date on the client and then pass it to the server. Either create a date in your GET and pass it or on POST do DateTime.UtcNow.
Or,you could pass dates and timezone to the server.
More details,you could refer to below article:
https://stackoverflow.com/questions/7577389/how-to-elegantly-deal-with-timezones
Best regards,
Yijing Sun