Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. JQuery datepicker

JQuery datepicker

Scheduled Pinned Locked Moved .NET (Core and Framework)
asp-netjavascriptdatabasepostgresqlhelp
17 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • pkfoxP pkfox

    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

    S Offline
    S Offline
    SeeSharp2
    wrote on last edited by
    #2

    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.

    pkfoxP 1 Reply Last reply
    0
    • S SeeSharp2

      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.

      pkfoxP Offline
      pkfoxP Offline
      pkfox
      wrote on last edited by
      #3

      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

      S 1 Reply Last reply
      0
      • pkfoxP pkfox

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        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

        pkfoxP 1 Reply Last reply
        0
        • L Lost User

          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

          pkfoxP Offline
          pkfoxP Offline
          pkfox
          wrote on last edited by
          #5

          The table column is of type date

          "I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP

          L 1 Reply Last reply
          0
          • pkfoxP pkfox

            The table column is of type date

            "I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            "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

            pkfoxP 2 Replies Last reply
            0
            • L Lost User

              "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

              pkfoxP Offline
              pkfoxP Offline
              pkfox
              wrote on last edited by
              #7

              Maybe Gerry thanks

              "I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP

              1 Reply Last reply
              0
              • L Lost User

                "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

                pkfoxP Offline
                pkfoxP Offline
                pkfox
                wrote on last edited by
                #8

                Hi Gerry I just called my API using postman and everything worked as expected so it's not the database.

                "I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP

                1 Reply Last reply
                0
                • pkfoxP pkfox

                  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

                  S Offline
                  S Offline
                  SeeSharp2
                  wrote on last edited by
                  #9

                  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.

                  pkfoxP 1 Reply Last reply
                  0
                  • S SeeSharp2

                    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.

                    pkfoxP Offline
                    pkfoxP Offline
                    pkfox
                    wrote on last edited by
                    #10

                    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

                    S 1 Reply Last reply
                    0
                    • pkfoxP pkfox

                      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

                      S Offline
                      S Offline
                      SeeSharp2
                      wrote on last edited by
                      #11

                      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.

                      pkfoxP 1 Reply Last reply
                      0
                      • S SeeSharp2

                        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.

                        pkfoxP Offline
                        pkfoxP Offline
                        pkfox
                        wrote on last edited by
                        #12

                        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

                        S 1 Reply Last reply
                        0
                        • pkfoxP pkfox

                          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

                          S Offline
                          S Offline
                          SeeSharp2
                          wrote on last edited by
                          #13

                          I do. I think the Json serializer is expecting the datetime to be in UTC format.

                          pkfoxP 1 Reply Last reply
                          0
                          • S SeeSharp2

                            I do. I think the Json serializer is expecting the datetime to be in UTC format.

                            pkfoxP Offline
                            pkfoxP Offline
                            pkfox
                            wrote on last edited by
                            #14

                            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

                            S 1 Reply Last reply
                            0
                            • pkfoxP pkfox

                              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

                              S Offline
                              S Offline
                              SeeSharp2
                              wrote on last edited by
                              #15

                              No problem. Glad you got it working.

                              pkfoxP 1 Reply Last reply
                              0
                              • S SeeSharp2

                                No problem. Glad you got it working.

                                pkfoxP Offline
                                pkfoxP Offline
                                pkfox
                                wrote on last edited by
                                #16

                                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

                                S 1 Reply Last reply
                                0
                                • pkfoxP pkfox

                                  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

                                  S Offline
                                  S Offline
                                  SeeSharp2
                                  wrote on last edited by
                                  #17

                                  I have not used the jquery datepicker in this way but this link seems to explain how to do it, How to apply jQuery DatePicker in ASP.NET MVC in Create and Edit View - Stack Overflow[^]

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups