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

  • Home
  • SEARCH
  • 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 839457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:27:59+00:00 2026-05-15T05:27:59+00:00

I have a date in this format: dd.mm.yyyy When I instantiate a JavaScript date

  • 0

I have a date in this format: dd.mm.yyyy

When I instantiate a JavaScript date with it, it gives me a NaN

In c# I can specify a date format, to say: here you have my string, it’s in this format, please make a Datetime of it.

Is this possible in JavaScript too? If not, is there an easy way?

I would prefer not to use a substring for day, substring for month etc. because my method must also be capable of german, italian, english etc. dates.

  • 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-05-15T05:27:59+00:00Added an answer on May 15, 2026 at 5:27 am

    You will need to create a function to extract the date parts and use them with the Date constructor.

    Note that this constructor treats months as zero based numbers (0=Jan, 1=Feb, ..., 11=Dec).

    For example:

    function parseDate(input) {
      var parts = input.match(/(\d+)/g);
      // note parts[1]-1
      return new Date(parts[2], parts[1]-1, parts[0]);
    }
    
    parseDate('31.05.2010');
    // Mon May 31 2010 00:00:00
    

    Edit: For handling a variable format you could do something like this:

    function parseDate(input, format) {
      format = format || 'yyyy-mm-dd'; // default format
      var parts = input.match(/(\d+)/g), 
          i = 0, fmt = {};
      // extract date-part indexes from the format
      format.replace(/(yyyy|dd|mm)/g, function(part) { fmt[part] = i++; });
    
      return new Date(parts[fmt['yyyy']], parts[fmt['mm']]-1, parts[fmt['dd']]);
    }
    
    parseDate('05.31.2010', 'mm.dd.yyyy');
    parseDate('31.05.2010', 'dd.mm.yyyy');
    parseDate('2010-05-31');
    

    The above function accepts a format parameter, that should include the yyyy mm and dd placeholders, the separators are not really important, since only digits are captured by the RegExp.

    You might also give a look to DateJS, a small library that makes date parsing painless…

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

Sidebar

Related Questions

I have a date in String format, mm/dd/yyyy I want to convert this to
I have this date format: <entry key=buildDate type=date value=now pattern=MM-dd-yyyy HH:mm:ss/> But ant gives
I have a date string in this format - DD-MM-YYYY this validates that successfully:
I have a string date like this: $date = 23/12/2011;//format: dd/mm/yyyy. I need each
I have the need to display a date in this format: dd/mm/yyyy. This is
I have this date as string with me 15-07-2011 which is in the format
I want to convert Long value to String or Date in this format dd/mm/YYYY.
How to validate particular format date string using Javascript? I have one date picker
I have a date returned in this format YYYY-MM-DD, e.g. 2011-04-29. Using jQuery how
I have a date in this format dd/m/yyyy (if the month is less than

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.