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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:56:35+00:00 2026-05-23T03:56:35+00:00

I am trying to add days to a given date using Javascript. I have

  • 0

I am trying to add days to a given date using Javascript. I have the following code:

function onChange(e) {
    var datepicker = $("#DatePicker").val();
    alert(datepicker);
    var joindate = new Date(datepicker);
    alert(joindate);
    var numberOfDaysToAdd = 1;
    joindate.setDate(joindate + numberOfDaysToAdd);
    var dd = joindate.getDate();
    var mm = joindate.getMonth() + 1;
    var y = joindate.getFullYear();
    var joinFormattedDate = dd + '/' + mm + '/' + y;
    $('.new').val(joinFormattedDate);
}

On first alert I get the date 24/06/2011 but on second alert I get Thu Dec 06 2012 00:00:00 GMT+0500 (Pakistan Standard Time) which is wrong I want it to remain 24/06/2011 so that I can add days to it. In my code I want my final output to be 25/06/2011.

Fiddle is @ http://jsfiddle.net/tassadaque/rEe4v/

  • 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-23T03:56:35+00:00Added an answer on May 23, 2026 at 3:56 am

    Date('string') will attempt to parse the string as m/d/yyyy. The string 24/06/2011 thus becomes Dec 6, 2012. Reason: 24 is treated as a month… 1 => January 2011, 13 => January 2012 hence 24 => December 2012. I hope you understand what I mean. So:

    var dmy = "24/06/2011".split("/");        // "24/06/2011" should be pulled from $("#DatePicker").val() instead
    var joindate = new Date(
        parseInt(dmy[2], 10),
        parseInt(dmy[1], 10) - 1,
        parseInt(dmy[0], 10)
    );
    alert(joindate);                          // Fri Jun 24 2011 00:00:00 GMT+0500 (West Asia Standard Time) 
    joindate.setDate(joindate.getDate() + 1); // substitute 1 with actual number of days to add
    alert(joindate);                          // Sat Jun 25 2011 00:00:00 GMT+0500 (West Asia Standard Time)
    alert(
        ("0" + joindate.getDate()).slice(-2) + "/" +
        ("0" + (joindate.getMonth() + 1)).slice(-2) + "/" +
        joindate.getFullYear()
    );
    

    Demo here

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

Sidebar

Related Questions

I'm trying to add days to a date and then compare to see if
I am trying to add TCMPortMapper (http://code.google.com/p/tcmportmapper/) I have linked the framework in the
I have been searching for days trying to figure out how to add dialog
I am trying to add a number of days to a date selector input
I'm trying add a tab to my web page that looks like this: Using
I'm trying to add the asynchronous version of the Google Analytics tracking code to
I'm trying to add leading zeros to the days and months in a date_select,
I am trying to add seven days to a Data object, however at some
I have the function below which takes a string from the datepicker and turns
I have been trying there last days to extend the default editor (java, xml,

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.