Get date from IE in UK format









up vote
0
down vote

favorite












In my html document I have a date field:



<input type="date" id="birthDate" class="date-picker">


I get this date in javascript like so:



var birthdate = new Date($('#birthDate').val());


and do some sums:



var today = new Date(Date.now());
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var bornDays = Math.floor(Math.abs((today.getTime() - birthdate.getTime()) / (oneDay)));


The user enters a date in DD/MM/YYYY format on the html page. In Chrome this works fine and gives me the correct number of days since birth 'bornDays'. IE however appears to interpret the entered date as being US format, i.e. MM/DD/YYYY so when I get the date into javascript it thinks the days are months and vice versa.
How can I specify that the date is in UK format when getting it from IE?



EXTRA CLARIFICATION:



If the user enters a date 09/11/2018 in the browser



In Chrome,
birthdate.getDate() returns 9



In IE,
birthdate.getDate() returns 11










share|improve this question























  • stackoverflow.com/questions/7372038/…
    – mplungjan
    13 hours ago










  • $(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' ); Link
    – R. García
    13 hours ago











  • @R.García but that is not the HTML5 one
    – mplungjan
    13 hours ago










  • @mplungjan Doesn't it make sense ?
    – R. García
    13 hours ago











  • @R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
    – Lightness Races in Orbit
    13 hours ago















up vote
0
down vote

favorite












In my html document I have a date field:



<input type="date" id="birthDate" class="date-picker">


I get this date in javascript like so:



var birthdate = new Date($('#birthDate').val());


and do some sums:



var today = new Date(Date.now());
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var bornDays = Math.floor(Math.abs((today.getTime() - birthdate.getTime()) / (oneDay)));


The user enters a date in DD/MM/YYYY format on the html page. In Chrome this works fine and gives me the correct number of days since birth 'bornDays'. IE however appears to interpret the entered date as being US format, i.e. MM/DD/YYYY so when I get the date into javascript it thinks the days are months and vice versa.
How can I specify that the date is in UK format when getting it from IE?



EXTRA CLARIFICATION:



If the user enters a date 09/11/2018 in the browser



In Chrome,
birthdate.getDate() returns 9



In IE,
birthdate.getDate() returns 11










share|improve this question























  • stackoverflow.com/questions/7372038/…
    – mplungjan
    13 hours ago










  • $(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' ); Link
    – R. García
    13 hours ago











  • @R.García but that is not the HTML5 one
    – mplungjan
    13 hours ago










  • @mplungjan Doesn't it make sense ?
    – R. García
    13 hours ago











  • @R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
    – Lightness Races in Orbit
    13 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











In my html document I have a date field:



<input type="date" id="birthDate" class="date-picker">


I get this date in javascript like so:



var birthdate = new Date($('#birthDate').val());


and do some sums:



var today = new Date(Date.now());
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var bornDays = Math.floor(Math.abs((today.getTime() - birthdate.getTime()) / (oneDay)));


The user enters a date in DD/MM/YYYY format on the html page. In Chrome this works fine and gives me the correct number of days since birth 'bornDays'. IE however appears to interpret the entered date as being US format, i.e. MM/DD/YYYY so when I get the date into javascript it thinks the days are months and vice versa.
How can I specify that the date is in UK format when getting it from IE?



EXTRA CLARIFICATION:



If the user enters a date 09/11/2018 in the browser



In Chrome,
birthdate.getDate() returns 9



In IE,
birthdate.getDate() returns 11










share|improve this question















In my html document I have a date field:



<input type="date" id="birthDate" class="date-picker">


I get this date in javascript like so:



var birthdate = new Date($('#birthDate').val());


and do some sums:



var today = new Date(Date.now());
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var bornDays = Math.floor(Math.abs((today.getTime() - birthdate.getTime()) / (oneDay)));


The user enters a date in DD/MM/YYYY format on the html page. In Chrome this works fine and gives me the correct number of days since birth 'bornDays'. IE however appears to interpret the entered date as being US format, i.e. MM/DD/YYYY so when I get the date into javascript it thinks the days are months and vice versa.
How can I specify that the date is in UK format when getting it from IE?



EXTRA CLARIFICATION:



If the user enters a date 09/11/2018 in the browser



In Chrome,
birthdate.getDate() returns 9



In IE,
birthdate.getDate() returns 11







javascript html date






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 13 hours ago

























asked 13 hours ago









Steve W

4621617




4621617











  • stackoverflow.com/questions/7372038/…
    – mplungjan
    13 hours ago










  • $(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' ); Link
    – R. García
    13 hours ago











  • @R.García but that is not the HTML5 one
    – mplungjan
    13 hours ago










  • @mplungjan Doesn't it make sense ?
    – R. García
    13 hours ago











  • @R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
    – Lightness Races in Orbit
    13 hours ago

















  • stackoverflow.com/questions/7372038/…
    – mplungjan
    13 hours ago










  • $(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' ); Link
    – R. García
    13 hours ago











  • @R.García but that is not the HTML5 one
    – mplungjan
    13 hours ago










  • @mplungjan Doesn't it make sense ?
    – R. García
    13 hours ago











  • @R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
    – Lightness Races in Orbit
    13 hours ago
















stackoverflow.com/questions/7372038/…
– mplungjan
13 hours ago




stackoverflow.com/questions/7372038/…
– mplungjan
13 hours ago












$(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' ); Link
– R. García
13 hours ago





$(".selector" ).datepicker( dateFormat: 'dd/mm/yyyy' ); Link
– R. García
13 hours ago













@R.García but that is not the HTML5 one
– mplungjan
13 hours ago




@R.García but that is not the HTML5 one
– mplungjan
13 hours ago












@mplungjan Doesn't it make sense ?
– R. García
13 hours ago





@mplungjan Doesn't it make sense ?
– R. García
13 hours ago













@R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
– Lightness Races in Orbit
13 hours ago





@R.García No, not really. That question was asking about a jQuery DatePicker. This one isn't. Furthermore this is why you should not answer questions in the comments section as it cannot be properly peer reviewed when wrong.
– Lightness Races in Orbit
13 hours ago













3 Answers
3






active

oldest

votes

















up vote
0
down vote













If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date constructor rather than hoping the Date constructor will be able to guess at the input format.



Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.






share|improve this answer



























    up vote
    0
    down vote













    Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.



    var currentTime = new Date();
    var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
    var day = gmt.getDate();
    var month = gmt.getMonth() + 1;
    var year = gmt.getFullYear();

    var dateString = day + '/' + month + '/' + year;





    share|improve this answer






















    • No, because getDate() returns the month value when in IE
      – Steve W
      13 hours ago










    • getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
      – SPlatten
      13 hours ago











    • What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
      – Steve W
      12 hours ago











    • Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
      – James Howell
      11 hours ago


















    up vote
    0
    down vote













    To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.



    Now, let's say you need to get the date out of a string.



    var day = moment("1995-12-25");
    moment().date(); //will gives you the date


    The above will give you the same answer across all browsers.



    MomentJS supports following browsers,




    Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.




    I hope you will find this answer helpful.



    Cheers.






    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224050%2fget-date-from-ie-in-uk-format%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date constructor rather than hoping the Date constructor will be able to guess at the input format.



      Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.






      share|improve this answer
























        up vote
        0
        down vote













        If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date constructor rather than hoping the Date constructor will be able to guess at the input format.



        Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.






        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date constructor rather than hoping the Date constructor will be able to guess at the input format.



          Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.






          share|improve this answer












          If you know that the string entered will be in DD-MM-YYYY form, parse it and hand its individual components to the Date constructor rather than hoping the Date constructor will be able to guess at the input format.



          Or, better yet, provide separate fields for day/month/year (or a calendar widget) so that you're not reliant on users to type a specifically-formatted string.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 13 hours ago









          Lightness Races in Orbit

          277k50445756




          277k50445756






















              up vote
              0
              down vote













              Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.



              var currentTime = new Date();
              var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
              var day = gmt.getDate();
              var month = gmt.getMonth() + 1;
              var year = gmt.getFullYear();

              var dateString = day + '/' + month + '/' + year;





              share|improve this answer






















              • No, because getDate() returns the month value when in IE
                – Steve W
                13 hours ago










              • getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
                – SPlatten
                13 hours ago











              • What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
                – Steve W
                12 hours ago











              • Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
                – James Howell
                11 hours ago















              up vote
              0
              down vote













              Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.



              var currentTime = new Date();
              var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
              var day = gmt.getDate();
              var month = gmt.getMonth() + 1;
              var year = gmt.getFullYear();

              var dateString = day + '/' + month + '/' + year;





              share|improve this answer






















              • No, because getDate() returns the month value when in IE
                – Steve W
                13 hours ago










              • getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
                – SPlatten
                13 hours ago











              • What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
                – Steve W
                12 hours ago











              • Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
                – James Howell
                11 hours ago













              up vote
              0
              down vote










              up vote
              0
              down vote









              Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.



              var currentTime = new Date();
              var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
              var day = gmt.getDate();
              var month = gmt.getMonth() + 1;
              var year = gmt.getFullYear();

              var dateString = day + '/' + month + '/' + year;





              share|improve this answer














              Could you store each part of the data - day, month and year in variables and then construct a string in the order you desire? That should work in all browsers.



              var currentTime = new Date();
              var gmt = new Date(currentTime.valueOf() + currentTime.getTimezoneOffset() * 60000);
              var day = gmt.getDate();
              var month = gmt.getMonth() + 1;
              var year = gmt.getFullYear();

              var dateString = day + '/' + month + '/' + year;






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 11 hours ago

























              answered 13 hours ago









              James Howell

              3222822




              3222822











              • No, because getDate() returns the month value when in IE
                – Steve W
                13 hours ago










              • getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
                – SPlatten
                13 hours ago











              • What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
                – Steve W
                12 hours ago











              • Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
                – James Howell
                11 hours ago

















              • No, because getDate() returns the month value when in IE
                – Steve W
                13 hours ago










              • getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
                – SPlatten
                13 hours ago











              • What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
                – Steve W
                12 hours ago











              • Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
                – James Howell
                11 hours ago
















              No, because getDate() returns the month value when in IE
              – Steve W
              13 hours ago




              No, because getDate() returns the month value when in IE
              – Steve W
              13 hours ago












              getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
              – SPlatten
              13 hours ago





              getDate() does not return the month value, according to w3schools.com/js/js_date_methods.asp
              – SPlatten
              13 hours ago













              What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
              – Steve W
              12 hours ago





              What I mean to say is that when a user enters the date in dd/mm/yyyy form in IE, getDate returns the mm value. In other browsers it correctly gets the dd value
              – Steve W
              12 hours ago













              Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
              – James Howell
              11 hours ago





              Added a GMT conversion. I've tried gmt.getMonth() in my VirtualBox version of IE11 and it returns the correct month for me.
              – James Howell
              11 hours ago











              up vote
              0
              down vote













              To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.



              Now, let's say you need to get the date out of a string.



              var day = moment("1995-12-25");
              moment().date(); //will gives you the date


              The above will give you the same answer across all browsers.



              MomentJS supports following browsers,




              Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.




              I hope you will find this answer helpful.



              Cheers.






              share|improve this answer
























                up vote
                0
                down vote













                To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.



                Now, let's say you need to get the date out of a string.



                var day = moment("1995-12-25");
                moment().date(); //will gives you the date


                The above will give you the same answer across all browsers.



                MomentJS supports following browsers,




                Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.




                I hope you will find this answer helpful.



                Cheers.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.



                  Now, let's say you need to get the date out of a string.



                  var day = moment("1995-12-25");
                  moment().date(); //will gives you the date


                  The above will give you the same answer across all browsers.



                  MomentJS supports following browsers,




                  Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.




                  I hope you will find this answer helpful.



                  Cheers.






                  share|improve this answer












                  To avoid various different interpretations in Date / Time, in various different browsers, it is encouraged to use a librabry such as MomentJS.



                  Now, let's say you need to get the date out of a string.



                  var day = moment("1995-12-25");
                  moment().date(); //will gives you the date


                  The above will give you the same answer across all browsers.



                  MomentJS supports following browsers,




                  Currently the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.




                  I hope you will find this answer helpful.



                  Cheers.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 11 hours ago









                  Anjana Silva

                  1,96712128




                  1,96712128



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224050%2fget-date-from-ie-in-uk-format%23new-answer', 'question_page');

                      );

                      Post as a guest














































































                      Popular posts from this blog

                      Use pre created SQLite database for Android project in kotlin

                      Darth Vader #20

                      Ondo