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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:10:16+00:00 2026-06-01T02:10:16+00:00

I have a problem that seems so senseless that I’m sure I’m missing something

  • 0

I have a problem that seems so senseless that I’m sure I’m missing something really stupid.
I have the following Javascript function that validates a date:

function validateDate(date){
    var re = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
    if(!re.test(date))
        return false;

    var separator = (date.indexOf("/") != -1) ? "/" : "-";
    var aux = date.split(separator);
    var day = parseInt(aux[0]);
    var month = parseInt(aux[1]);
    var year = parseInt(aux[2]);
    alert(aux[0]+" "+aux[1]+" "+aux[2]);
    var dateTest = new Date(year,month-1,day);
    alert(dateTest); //2nd alert
    if(dateTest.getDate() != day)
        return false;
    if(dateTest.getMonth()+1!= month)
        return false;
    if(dateTest.getFullYear() != year)
        return false;

    return true;    
}

the first alert always shows the correct values.
if the incoming date is for example 05/07/2011, everything works fine. The second alert shows "Tue Jul 5 00:00:00 UTC+0200 2011" which is right.
but now, if i change the date month to august or september, the created date is wrong. for example, with date 05/08/2011, the second alert will show "Sun Dec 5 00:00:00 UTC+0100 2010".

anyone knows what could be happening??

  • 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-01T02:10:18+00:00Added an answer on June 1, 2026 at 2:10 am

    Make sure you supply a radix to parseInt. If you don’t, it will “guess” based on the string. In this case, your 08 is being parsed as an octal value because of the prefixed zero and you get 0 back.

    var day = parseInt(aux[0], 10);
    var month = parseInt(aux[1], 10);
    var year = parseInt(aux[2], 10);
    

    Supplying a base ten number will get you the correct result.

    //Parsing numbers:
    parseInt("06");  // 6, valid octal
    parseInt("07");  // 7, valid octal
    parseInt("08");  // 0, invalid octal
    parseInt("09");  // 0, invalid octal
    parseInt("10");  // 10, parsed as decimal
    parseInt("11");  // 11, parsed as decimal
    parseInt("12");  // 12, parsed as decimal
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that seems like its a result of a deadlock-situation. Whe
I have a problem that I have not faced before: It seems that the
I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map
I have an issue that seems like very flaky behavour, is this a problem
This seems like a simple problem: I have a WF4 activity that guides the
I have a problem that seems like there should be a simple solution but
we have the problem that ShowHelp seems to fail under Vista and Windows Server
I have this classic problem that seems impossible to solve for me. I just
Have a problem that seems easy on paper but i'm having a big problem
I have a problem that seems very related to that in another post, but

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.