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. Other Discussions
  3. The Weird and The Wonderful
  4. How I learned to stop worrying & love The Error

How I learned to stop worrying & love The Error

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpquestioncsharpjavascripthtml
3 Posts 3 Posters 23 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.
  • R Offline
    R Offline
    raddevus
    wrote on last edited by
    #1

    I've just painfully (while developing an app) stumbled upon this terrible little bug in the HTML5 Date control. TLDR; If you set the value of your HTML5 date input control to today's date, it will display that date. However, when you go to read the date using the same property of the input control that you used to set it, you __may__ get a date that is one day less than the date you set!!!! Code and snapshots below... If you add the basic Date input control to your page:

    You'll see something like what is shown in this snapshot[^]. Notice that the date is not set. To set the Date to the current date you need JavaScript (of course). So do something like the following:

    document.querySelector("#mainDate").valueAsDate = new Date();

    Now the Date control will be set to the current date for you, based upon your local date/time. The control looks like the following snapshot for me now[^]. Let's Read the Value Back, Shall We? Let's add some code to read the value back -- even though it is obvious that the value will be 03-12-2023, right? Right? Right!?! Insert maniacal laughter here!!! Here's the Extremely Simple JavaScript Code

    function showDate(){
    alert(document.querySelector("#mainDate").valueAsDate);
    }

    The Date Reported is One Day Behind You can see in this snapshot that my system actually[^] reports that it is not 03-12-2023 (it actually is IRL (In Real Life), but it reports it as a time on 03-11-2023. Inspect My Simple Code At JSFiddle If you can't believe my snapshots, take a look at the code[^] and you can see that I simply read the valueAsDate from the date input control and pop up the value in the alert() box. You can also see my code at plunkr[

    J D 2 Replies Last reply
    0
    • R raddevus

      I've just painfully (while developing an app) stumbled upon this terrible little bug in the HTML5 Date control. TLDR; If you set the value of your HTML5 date input control to today's date, it will display that date. However, when you go to read the date using the same property of the input control that you used to set it, you __may__ get a date that is one day less than the date you set!!!! Code and snapshots below... If you add the basic Date input control to your page:

      You'll see something like what is shown in this snapshot[^]. Notice that the date is not set. To set the Date to the current date you need JavaScript (of course). So do something like the following:

      document.querySelector("#mainDate").valueAsDate = new Date();

      Now the Date control will be set to the current date for you, based upon your local date/time. The control looks like the following snapshot for me now[^]. Let's Read the Value Back, Shall We? Let's add some code to read the value back -- even though it is obvious that the value will be 03-12-2023, right? Right? Right!?! Insert maniacal laughter here!!! Here's the Extremely Simple JavaScript Code

      function showDate(){
      alert(document.querySelector("#mainDate").valueAsDate);
      }

      The Date Reported is One Day Behind You can see in this snapshot that my system actually[^] reports that it is not 03-12-2023 (it actually is IRL (In Real Life), but it reports it as a time on 03-11-2023. Inspect My Simple Code At JSFiddle If you can't believe my snapshots, take a look at the code[^] and you can see that I simply read the valueAsDate from the date input control and pop up the value in the alert() box. You can also see my code at plunkr[

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      There is no such thing as a timestamp without a timezone. Does not matter how you do it. All programming languages. All databases. Even when it is not obvious. Even when it is not defined. Even if you just write it on a piece of paper. Myself I am not even sure if dates (not timestamps) exist without a timezone. Certainly my birthday is just as useable here as it is halfway around the world. But if I am supposed to get a something free from a international company on my birthday every year as a swag then when does it show up?

      1 Reply Last reply
      0
      • R raddevus

        I've just painfully (while developing an app) stumbled upon this terrible little bug in the HTML5 Date control. TLDR; If you set the value of your HTML5 date input control to today's date, it will display that date. However, when you go to read the date using the same property of the input control that you used to set it, you __may__ get a date that is one day less than the date you set!!!! Code and snapshots below... If you add the basic Date input control to your page:

        You'll see something like what is shown in this snapshot[^]. Notice that the date is not set. To set the Date to the current date you need JavaScript (of course). So do something like the following:

        document.querySelector("#mainDate").valueAsDate = new Date();

        Now the Date control will be set to the current date for you, based upon your local date/time. The control looks like the following snapshot for me now[^]. Let's Read the Value Back, Shall We? Let's add some code to read the value back -- even though it is obvious that the value will be 03-12-2023, right? Right? Right!?! Insert maniacal laughter here!!! Here's the Extremely Simple JavaScript Code

        function showDate(){
        alert(document.querySelector("#mainDate").valueAsDate);
        }

        The Date Reported is One Day Behind You can see in this snapshot that my system actually[^] reports that it is not 03-12-2023 (it actually is IRL (In Real Life), but it reports it as a time on 03-11-2023. Inspect My Simple Code At JSFiddle If you can't believe my snapshots, take a look at the code[^] and you can see that I simply read the valueAsDate from the date input control and pop up the value in the alert() box. You can also see my code at plunkr[

        D Offline
        D Offline
        DrWalter PE
        wrote on last edited by
        #3

        raddevus wrote:

        I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.

        I agree with whoever said,Programming is the act of debugging a blank page. Maybe Knuth?

        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