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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:49:29+00:00 2026-05-23T07:49:29+00:00

I trying to add days / months / year to a given date and

  • 0

I trying to add days / months / year to a given date and map it to an input field

 
        var d = new Date();
        d.setDate(15);
        d.setMonth(06);
        d.setYear(2011);

        document.getElementById("test").innerHTML=d;

        d.setDate(d.getDate()+20);

        document.getElementById("test").innerHTML+="
"+d.getDate()+"/"+d.getMonth()+"/"+d.getYear("YY");

this actually prints out


Fri Jul 15 2011 12:45:48 GMT+0530 (India Standard Time)
4/7/111

actually this is wrong.. it should print out 5/7/2011.. i think by default the system takes as “30” days for a month and adds the +20 days.. but actually Jun has 30 days so that result should be 5/7/2011..

any suggestion about what goes wrong in here.. any alternative for this?

  • 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-23T07:49:29+00:00Added an answer on May 23, 2026 at 7:49 am

    At the first, you have better to use getFullYear to get year as 2011. You did get number from getDate() and add 20. This break Date. You should get long value from getTime(), and add milli-seconds.

    <div id="test"></div>
    <script>
        var d = new Date();
        d.setDate(15);
        d.setMonth(06);
        d.setFullYear(2011);
        document.getElementById("test").innerHTML+=" "+d.getDate()+"/"+d.getMonth()+"/"+d.getFullYear();
        d.setTime(d.getTime()+1000*60*60*24*20);
        document.getElementById("test").innerHTML+=" "+d.getDate()+"/"+d.getMonth()+"/"+d.getFullYear();
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a number of days to a date selector input
I'm trying to add days to a date and then compare to see if
I'm trying to add leading zeros to the days and months in a date_select,
I am trying to add 60 days from the current date in milliseconds. I
For two days I have been trying to add new customer attribute to the
Im new to asp.net mvc. I'm trying add new model class but it got
var dateObj = new Date(); var val = dateObj.getTime(); //86400 * 1000 * 3
Hi I am trying to add 31 days to 'myDate' which is the current
I'm trying to do 2 things. Calculate number of business days to date in
I am trying use strtotime and date functions within a class to add 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.