Converting a full date string like “Saturday 23rd March 2019” to Javascript Date()How do you get a timestamp in JavaScript?var functionName = function() vs function functionName() Where can I find documentation on formatting a date in JavaScript?Convert a string to an integer in JavaScript?How to replace all occurrences of a string in JavaScriptConvert form data to JavaScript object with jQueryDetecting an “invalid date” Date instance in JavaScriptevent.preventDefault() vs. return falseStoring Objects in HTML5 localStorageConverting a string to a date in JavaScript

How to laser-level close to a surface

Quotient of Three Dimensional Torus by Permutation on Coordinates

Will this series of events work to drown the Tarrasque?

Would a "ring language" be possible?

Should I twist DC power and ground wires from a power supply?

Bookshelves: the intruder

Is it possible to determine from only a photo of a cityscape whether it was taken close with wide angle or from a distance with zoom?

Alternative classical explanation of the Stern-Gerlach Experiment?

Is it standard to have the first week's pay indefinitely withheld?

Why we learn compiler?

Are there any symmetric cryptosystems based on computational complexity assumptions?

What should I wear to go and sign an employment contract?

When did Britain learn about the American Declaration of Independence?

Is there a language that let's you use a try block without a catch block?

How do I balance a campaign consisting of four kobold PCs?

How to customize the pie chart background in PowerPoint?

Divisor Rich and Poor Numbers

Parse a C++14 integer literal

Can an airline pilot be prosecuted for killing an unruly passenger who could not be physically restrained?

Does a windmilling propeller create more drag than a stopped propeller in an engine out scenario

Have GoT's showrunners reacted to the poor reception of the final season?

What is the probability that two cards drawn from a deck are both face cards and at least one is red?

Why are there five extra turns in tournament Magic?

Hotel booking: Why is Agoda much cheaper than booking.com?



Converting a full date string like “Saturday 23rd March 2019” to Javascript Date()


How do you get a timestamp in JavaScript?var functionName = function() vs function functionName() Where can I find documentation on formatting a date in JavaScript?Convert a string to an integer in JavaScript?How to replace all occurrences of a string in JavaScriptConvert form data to JavaScript object with jQueryDetecting an “invalid date” Date instance in JavaScriptevent.preventDefault() vs. return falseStoring Objects in HTML5 localStorageConverting a string to a date in JavaScript






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















How can I convert a string like "Saturday 23rd March 2019" to Javascript date?



For some reason it says invalid date and other questions similar to this are trying to convert strings like "23-03-2019 10:00" etc to Date, whereas this is more of a full date string.










share|improve this question




























    -2















    How can I convert a string like "Saturday 23rd March 2019" to Javascript date?



    For some reason it says invalid date and other questions similar to this are trying to convert strings like "23-03-2019 10:00" etc to Date, whereas this is more of a full date string.










    share|improve this question
























      -2












      -2








      -2








      How can I convert a string like "Saturday 23rd March 2019" to Javascript date?



      For some reason it says invalid date and other questions similar to this are trying to convert strings like "23-03-2019 10:00" etc to Date, whereas this is more of a full date string.










      share|improve this question














      How can I convert a string like "Saturday 23rd March 2019" to Javascript date?



      For some reason it says invalid date and other questions similar to this are trying to convert strings like "23-03-2019 10:00" etc to Date, whereas this is more of a full date string.







      javascript date data-conversion






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 17:36









      ScoopScoop

      304




      304






















          2 Answers
          2






          active

          oldest

          votes


















          0














          It's actually the "rd" of 23rd that's causing the issue. Otherwise the string as is will convert to a date. I've used a regex replace to substitute "23rd" with "23". Also tossed in another example to capture "1st" as well.






          var dateString = "Saturday 23rd March 2019";

          var cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));

          dateString = "Friday 1st March 2019";

          cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));








          share|improve this answer























          • If you're going to the trouble of modifying the string to give it to a parser, you might as well just parse it yourself, it's just 3 lines of code. :-)

            – RobG
            Mar 23 at 21:26


















          1














          Best bet would be use a library like moment js to parse that string and tell it the format expected :






          const str = "Saturday 23rd March 2019";
          const m = moment(str, "dddd Do MMMM YYYY");

          console.log(m.toDate())

          <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>





          If the formatting is not consistent you will need to write a custom parser which won't be a trivial exercise.






          share|improve this answer























          • "If the formatting is not consistent…" then any parser will struggle, as evidenced by the vagaries of built–in parsers. ;-)

            – RobG
            Mar 23 at 21:24











          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',
          autoActivateHeartbeat: false,
          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%2f55316542%2fconverting-a-full-date-string-like-saturday-23rd-march-2019-to-javascript-date%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It's actually the "rd" of 23rd that's causing the issue. Otherwise the string as is will convert to a date. I've used a regex replace to substitute "23rd" with "23". Also tossed in another example to capture "1st" as well.






          var dateString = "Saturday 23rd March 2019";

          var cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));

          dateString = "Friday 1st March 2019";

          cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));








          share|improve this answer























          • If you're going to the trouble of modifying the string to give it to a parser, you might as well just parse it yourself, it's just 3 lines of code. :-)

            – RobG
            Mar 23 at 21:26















          0














          It's actually the "rd" of 23rd that's causing the issue. Otherwise the string as is will convert to a date. I've used a regex replace to substitute "23rd" with "23". Also tossed in another example to capture "1st" as well.






          var dateString = "Saturday 23rd March 2019";

          var cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));

          dateString = "Friday 1st March 2019";

          cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));








          share|improve this answer























          • If you're going to the trouble of modifying the string to give it to a parser, you might as well just parse it yourself, it's just 3 lines of code. :-)

            – RobG
            Mar 23 at 21:26













          0












          0








          0







          It's actually the "rd" of 23rd that's causing the issue. Otherwise the string as is will convert to a date. I've used a regex replace to substitute "23rd" with "23". Also tossed in another example to capture "1st" as well.






          var dateString = "Saturday 23rd March 2019";

          var cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));

          dateString = "Friday 1st March 2019";

          cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));








          share|improve this answer













          It's actually the "rd" of 23rd that's causing the issue. Otherwise the string as is will convert to a date. I've used a regex replace to substitute "23rd" with "23". Also tossed in another example to capture "1st" as well.






          var dateString = "Saturday 23rd March 2019";

          var cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));

          dateString = "Friday 1st March 2019";

          cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));








          var dateString = "Saturday 23rd March 2019";

          var cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));

          dateString = "Friday 1st March 2019";

          cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));





          var dateString = "Saturday 23rd March 2019";

          var cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));

          dateString = "Friday 1st March 2019";

          cleanDateString = dateString.replace(/(d+)(rd|st|nd|th)/, "$1");

          console.log(new Date(cleanDateString));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 17:54









          Doug FDoug F

          8202917




          8202917












          • If you're going to the trouble of modifying the string to give it to a parser, you might as well just parse it yourself, it's just 3 lines of code. :-)

            – RobG
            Mar 23 at 21:26

















          • If you're going to the trouble of modifying the string to give it to a parser, you might as well just parse it yourself, it's just 3 lines of code. :-)

            – RobG
            Mar 23 at 21:26
















          If you're going to the trouble of modifying the string to give it to a parser, you might as well just parse it yourself, it's just 3 lines of code. :-)

          – RobG
          Mar 23 at 21:26





          If you're going to the trouble of modifying the string to give it to a parser, you might as well just parse it yourself, it's just 3 lines of code. :-)

          – RobG
          Mar 23 at 21:26













          1














          Best bet would be use a library like moment js to parse that string and tell it the format expected :






          const str = "Saturday 23rd March 2019";
          const m = moment(str, "dddd Do MMMM YYYY");

          console.log(m.toDate())

          <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>





          If the formatting is not consistent you will need to write a custom parser which won't be a trivial exercise.






          share|improve this answer























          • "If the formatting is not consistent…" then any parser will struggle, as evidenced by the vagaries of built–in parsers. ;-)

            – RobG
            Mar 23 at 21:24















          1














          Best bet would be use a library like moment js to parse that string and tell it the format expected :






          const str = "Saturday 23rd March 2019";
          const m = moment(str, "dddd Do MMMM YYYY");

          console.log(m.toDate())

          <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>





          If the formatting is not consistent you will need to write a custom parser which won't be a trivial exercise.






          share|improve this answer























          • "If the formatting is not consistent…" then any parser will struggle, as evidenced by the vagaries of built–in parsers. ;-)

            – RobG
            Mar 23 at 21:24













          1












          1








          1







          Best bet would be use a library like moment js to parse that string and tell it the format expected :






          const str = "Saturday 23rd March 2019";
          const m = moment(str, "dddd Do MMMM YYYY");

          console.log(m.toDate())

          <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>





          If the formatting is not consistent you will need to write a custom parser which won't be a trivial exercise.






          share|improve this answer













          Best bet would be use a library like moment js to parse that string and tell it the format expected :






          const str = "Saturday 23rd March 2019";
          const m = moment(str, "dddd Do MMMM YYYY");

          console.log(m.toDate())

          <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>





          If the formatting is not consistent you will need to write a custom parser which won't be a trivial exercise.






          const str = "Saturday 23rd March 2019";
          const m = moment(str, "dddd Do MMMM YYYY");

          console.log(m.toDate())

          <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>





          const str = "Saturday 23rd March 2019";
          const m = moment(str, "dddd Do MMMM YYYY");

          console.log(m.toDate())

          <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 17:48









          charlietflcharlietfl

          143k1395126




          143k1395126












          • "If the formatting is not consistent…" then any parser will struggle, as evidenced by the vagaries of built–in parsers. ;-)

            – RobG
            Mar 23 at 21:24

















          • "If the formatting is not consistent…" then any parser will struggle, as evidenced by the vagaries of built–in parsers. ;-)

            – RobG
            Mar 23 at 21:24
















          "If the formatting is not consistent…" then any parser will struggle, as evidenced by the vagaries of built–in parsers. ;-)

          – RobG
          Mar 23 at 21:24





          "If the formatting is not consistent…" then any parser will struggle, as evidenced by the vagaries of built–in parsers. ;-)

          – RobG
          Mar 23 at 21:24

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316542%2fconverting-a-full-date-string-like-saturday-23rd-march-2019-to-javascript-date%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript