JQuery datepicker
-
I have an ASP Net Core Web app which uses Razor pages, on one of the pages I use a datepicker as part of a data entry form, I have a problem where the date I select is somehow changing to the day before by the time it hits the database ( Postgresql ). In my controller action the date value received is correct - I'm using npgsql as the data provider - any idea what could be causing this ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
-
I have an ASP Net Core Web app which uses Razor pages, on one of the pages I use a datepicker as part of a data entry form, I have a problem where the date I select is somehow changing to the day before by the time it hits the database ( Postgresql ). In my controller action the date value received is correct - I'm using npgsql as the data provider - any idea what could be causing this ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
I have seen this before and I don't recall where it was. But what is likely happening is the value 2021-06-11 00:00:00 is getting passed but somewhere it is then getting translated into your time zone, which I am guessing is -x from UTC. And so then it becomes, for example, 2021-06-10 20:00:00, if you were on the East Coast in the US. You'll have to keep tracking it until you find where it changes.
-
I have seen this before and I don't recall where it was. But what is likely happening is the value 2021-06-11 00:00:00 is getting passed but somewhere it is then getting translated into your time zone, which I am guessing is -x from UTC. And so then it becomes, for example, 2021-06-10 20:00:00, if you were on the East Coast in the US. You'll have to keep tracking it until you find where it changes.
Hi and thanks for replying. So you have a better understanding I list out below what is happening.. The data is input and posted using a Razor page. The Web app Controller action issues a TryUpdateModelAsync which populates an instance of my class with the form data - at this point the date in the class is correct. I then pass my class object to an API running on my local LAN which pushes the data to a database , at this point the date in the class object has changed. So on it's journey to the API it is somehow changing the date. Both the Web app and the API are hosted on a Linux box.
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
-
I have an ASP Net Core Web app which uses Razor pages, on one of the pages I use a datepicker as part of a data entry form, I have a problem where the date I select is somehow changing to the day before by the time it hits the database ( Postgresql ). In my controller action the date value received is correct - I'm using npgsql as the data provider - any idea what could be causing this ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
Is it a "Timestamp"?
Quote:
Note: The SQL standard requires that writing just timestamp be equivalent to timestamp without time zone, and PostgreSQL honors that behavior. (Releases prior to 7.3 treated it as timestamp with time zone.) timestamptz is accepted as an abbreviation for timestamp with time zone; this is a PostgreSQL extension.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
Is it a "Timestamp"?
Quote:
Note: The SQL standard requires that writing just timestamp be equivalent to timestamp without time zone, and PostgreSQL honors that behavior. (Releases prior to 7.3 treated it as timestamp with time zone.) timestamptz is accepted as an abbreviation for timestamp with time zone; this is a PostgreSQL extension.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
The table column is of type date
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
"date" has a "one day resolution". Perhaps a (internal) rounding thing going from one representation to another.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
"date" has a "one day resolution". Perhaps a (internal) rounding thing going from one representation to another.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
"date" has a "one day resolution". Perhaps a (internal) rounding thing going from one representation to another.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
Hi and thanks for replying. So you have a better understanding I list out below what is happening.. The data is input and posted using a Razor page. The Web app Controller action issues a TryUpdateModelAsync which populates an instance of my class with the form data - at this point the date in the class is correct. I then pass my class object to an API running on my local LAN which pushes the data to a database , at this point the date in the class object has changed. So on it's journey to the API it is somehow changing the date. Both the Web app and the API are hosted on a Linux box.
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
-
pkfox wrote:
So on it's journey to the API it is somehow changing the date.
Are you using a JSON serializer? That can do it.
Yes the API uses the NewtonSoft serialiser / deserialiser - weird that the date is always a day out. But as I said in another reply - I called the API from Postman ( hard coded JSON in the body ) and it worked as expected.
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
-
Yes the API uses the NewtonSoft serialiser / deserialiser - weird that the date is always a day out. But as I said in another reply - I called the API from Postman ( hard coded JSON in the body ) and it worked as expected.
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
pkfox wrote:
I called the API from Postman ( hard coded JSON in the body ) and it worked as expected.
Precisely. JSON sees 2021-06-14 00:00:00 AS UTC time and converts it for you. I don't remember how to get around it but if you google it, you should find it.
-
pkfox wrote:
I called the API from Postman ( hard coded JSON in the body ) and it worked as expected.
Precisely. JSON sees 2021-06-14 00:00:00 AS UTC time and converts it for you. I don't remember how to get around it but if you google it, you should find it.
-
I use RestSharp in my API which I believe uses a JsonSerialiser / JsonDeserialiser - do you think this is where the problem lies ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
-
I think I've got things working. After your suggestion that it could be a serializing problem I googled and found a post written by one of the RestSharp developers regarding the use of custom serializers, he gave some sample code which I duly cut'n pasted and it seems to have done the trick. Thanks very much for pointing me in the right direction.
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
-
I think I've got things working. After your suggestion that it could be a serializing problem I googled and found a post written by one of the RestSharp developers regarding the use of custom serializers, he gave some sample code which I duly cut'n pasted and it seems to have done the trick. Thanks very much for pointing me in the right direction.
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
-
While I have your ear - how can I set the datepicker to the date value in my model when I'm editing - I've tried the code below but it just shows a text box with the string dd-mm-yyy in until I click in it and then it pops up
@Html.TextBoxFor(m => m.DateUsed, new { @class = "datepicker", Type = "date", Value = Model.DateUsed }) -- DateUsed is my DateTime property
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
-
While I have your ear - how can I set the datepicker to the date value in my model when I'm editing - I've tried the code below but it just shows a text box with the string dd-mm-yyy in until I click in it and then it pops up
@Html.TextBoxFor(m => m.DateUsed, new { @class = "datepicker", Type = "date", Value = Model.DateUsed }) -- DateUsed is my DateTime property
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP