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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:41:45+00:00 2026-05-15T23:41:45+00:00

Possible Duplicate: Workarounds for JavaScript parseInt octal bug I’m parsing a string to check

  • 0

Possible Duplicate:
Workarounds for JavaScript parseInt octal bug

I’m parsing a string to check if it’s a date, and by chance we now discovered that my method doesn’t work for dates in august or september. This is what I do (the input isn’t really hard-coded, obviously, but for brevity…):

var str = '2010-08-26 14:53';
var data = str.split(' ');  // ['2010-08-26', '14:53']
var date = data[0].split('-'); // ['2010', '08', '26]
var time = data[1].split(':'); // ['14', '53']

var yyyy = parseInt(date[0]); // 2010

// THIS IS WHERE STRANGE THINGS HAPPEN:
var MM = parseInt(date[1]); // 0 - not 08 or 8, as expected!
console.log(date[1]); // prints "08" (with quotes)
console.log(date[1].toString()); // prints 08 (no quotes)
console.log(parseInt(date[1].toString())); // prints 0 (!)

This problem arises for august and september, and for the 8th and 9th every month – that is, when either "08" or "09" is being parsed to integer, 0 is returned instead of 8 or 9. The code works for both lower (e.g. "07") and higher (e.g. "10") integers (at least within expected date ranges…)

What am I doing wrong?

  • 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-15T23:41:46+00:00Added an answer on May 15, 2026 at 11:41 pm

    Use

    parseInt(date[1], 10)
    

    to make sure the string is interpreted as base 10 (decimal).

    Otherwise, it is interpreted as base 8 (octal) if it starts with "0", or as base 16 (hexadecimal) if it starts with "0x".

    In fact, you should always include the base argument to avoid these kinds of bugs.

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

Sidebar

Ask A Question

Stats

  • Questions 524k
  • Answers 524k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer the general setup of swfAddress is to work with the… May 16, 2026 at 9:55 pm
  • Editorial Team
    Editorial Team added an answer This issue might be specific to my site, but perhaps… May 16, 2026 at 9:55 pm
  • Editorial Team
    Editorial Team added an answer http://code.google.com/p/appdailysales/ was just updated to support the Sept 2010 iTunes… May 16, 2026 at 9:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Possible Duplicate: How to detect if JavaScript is disabled? I have a website which
Possible Duplicate: Is there a CSS parent selector? I know this is a shot
Possible Duplicate: Any way to access array directly after method call? In C# and
Possible Duplicate: Anyone know a good workaround for the lack of an enum generic
Possible Duplicate: Why can’t I catch a generic exception in C#? I have been
Possible Duplicate: C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived> I have D1 and D2
Possible Duplicate: 'Contains()' workaround using Linq to Entities? I am using the System.Linq.Dynamic library
Possible Duplicate: Should I learn C before learning C++? As a professional (Java) programmer
Possible Duplicate: How do you give a C# Auto-Property a default value? Hi all:
Possible Duplicate: How to copy part of an array to another array in C#

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.