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 9258975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:32:35+00:00 2026-06-18T12:32:35+00:00

I have a form where users insert a date ( Edit : the input

  • 0

I have a form where users insert a date
(Edit: the input is copied form documents “as it is” so the formatting my vary)

“2012 12 01”

“2012-12-01”

“2012.12.01”

“01.15.2012”

also some not friendly (but FAST for typing!) inputs like:

“01122012” // 01 12 2012

“011212” // 01 12 2012

The input format is not fixed so I should make the bast out of what I get …

Of course there is some priority:

“12.12.12” should be parsed to yy.mm.dd IF VALID, or to dd.mm.yy as second option.

Most of the ready functions work with “properly formated” content .. so I need a alghorithm
(or good example code from parsers in other lanuages)

  • 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-18T12:32:37+00:00Added an answer on June 18, 2026 at 12:32 pm

    You could do this “straight forward” like:

    var dateString; // user input date
    if(dateString.split(" ").length == 3){
        // you have "yyyy mm dd" format
    } else if(dateString.split("-").length == 3){
        // you have yyyy-mm-dd format
    } else if(dateString.split(".").length == 3){
        // you have "yyyy.mm.dd" or "mm.dd.yyyy" format
    } else {
        // suppose you have "yyyymmdd" or "mmddyyyy" format
    }
    

    In the cases where you can have two different formats you have to check the day, year and month values if they are a valid year. If so, you can build the date, otherwise try the other way.

    For the yyyymmdd and mmddyyyy combinations you can use the substr() function on the string to extract the day, year and month.

    However, you always have to take into account that the user input can be something incorrect like “12 March 2012” or “abcdefg”, but I would simply wrap the whole functionality into a try-catch block.

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

Sidebar

Related Questions

I have a form where users can add input fields with jQuery. <input type="text"
I have a dynamic form that users can add/delete sets of input fields. I
I have a form that allows users to enter a date of birth: ie:
I have a form which captures a date that the user input in a
I have a form which users must fill out and submit. The controller action
I have a form which users can add controls to and when they right
I have a form where users can modify a collection of objects using a
I have a form where users can enter the names and emails addresses of
Let's say I have a form where users can search for people whose name
On my site, I have a form that users fill out to become 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.