Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:23:02+00:00 2026-06-08T11:23:02+00:00

I have a string which is allways in this format: 7 May 2012 or

  • 0

I have a string which is allways in this format: 7 May 2012 or 17 May 2012
My goal is to parse this string and get the date in this format: yyyy-mm-dd

So, my example 7 May 2012 will become 2012-05-07 and 17 May 2012 will become 2012-05-17

I have tryed with

Date.parse("7 May 2012", "yyyy-mm-dd") 

but the result is:

Sun May 20 2012 00:00:00 GMT+0200 (CEST)

Thank you very much for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:23:05+00:00Added an answer on June 8, 2026 at 11:23 am

    I don’t know where you got that Date.parse call, JavaScript’s Date.parse has no second argument.

    To do this, you’ll need to parse the string yourself, or use MomentJS or similar to do it for you. If you want to parse it yourself, you’ll probably want a regular expression and a lookup table (for the month names). The regex would be along these lines:

    var parts = /^\s*(\d+)\s+([A-Za-z]+)\s+(\d+)\s*$/.exec(str);
    

    …where you’d end up with parts[0] being the day, parts[1] the month name, and parts[2] the year. Then just convert the month to lower or upper case, and use a lookup table to map month name to month number, something along these lines:

    var months = {
        "jan": 0,
        "january": 0,
        "feb": 1,
        "february": 1,
        "may": 4,
        // ...
        "dec": 11,
        "december": 11
    };
    var parts = /^\s*(\d+)\s+([A-Za-z]+)\s+(\d+)\s*$/.exec(str);
    var dt;
    if (parts) {
        parts[2] = months[parts[2].toLowerCase()];
        if (typeof parts[2] !== "undefined") {
            dt = new Date(parseInt(parts[3], 10),
                          parts[2],
                          parseInt(parts[1], 10));
        }
    }
    

    Live example | source

    Then you can format the resulting Date object. (Again, there are libs to help there.)

    Or, of course, never actually make a Date and just format directly from parts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have URLs which always end on a number, for example: String url =
I have a string which is in the following format, When there is a
I have a string which typically is in the format : 0xFF . I'll
I have a string which looks like this a 3e,6s,1d,3g,22r,7c 3g,5r,9c 19.3 , how
I have productID=ab1002 which is in string format. productID is not always start with
I have a string that occurs in this format: .word 40 I would like
I have a String which has the following format: 2011-08-19T00:00:00 and I want now
I have problem with date function in php. If I supply string in format
I have a string which is of about 1mb size. The requirement is to
I have a string which varies everytime it is input as it is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.