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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:24:58+00:00 2026-06-10T11:24:58+00:00

right now this code works for tomorrow and next month – weekend use to

  • 0

right now this code works for tomorrow and next month – weekend use to work , except now that it is approaching the end of the month it is causing an error. my startdate is set to 8/31/12 and enddate is 8/34/12 (which is obivously going to throw an error when converted into DateTime in Sql.)

I am successfully doing math to add a day , and to add a month , but when it comes to adding days into the next month it breaks. I think I understand why this is hapening , it is getting date – “29” turning it to into int then adding – I suppose I will get the same problem for “next month” in December.

My question is what is the proper way (or any working way) to add days to javascript date, where it understands the days of the month.

        var d = new Date();
        var startdate;
        var enddate;

         if ($('._tomorrow').attr("checked") == "checked") {
                startdate = [d.getMonth() + 1, d.getDate() + 1, d.getFullYear()].join('/');
                enddate = [d.getMonth() + 1, d.getDate() + 2, d.getFullYear()].join('/');
            }
            if ($('._weekend').attr("checked") == "checked") {
                startdate = [d.getMonth() + 1, d.getDate() + 6 - d.getDay(), d.getFullYear()].join('/');
                enddate = [d.getMonth() + 1, ( d.getDate() + 6 - d.getDay()) + 2, d.getFullYear()].join('/');
            }
            if ($('._nextmonth').attr("checked") == "checked") {
                startdate = [d.getMonth() + 2, 1, d.getFullYear()].join('/');
                enddate = [d.getMonth() + 2, 29 , d.getFullYear()].join('/');
            }
  • 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-10T11:25:00+00:00Added an answer on June 10, 2026 at 11:25 am

    To add a specified number of days, create a new Date object and then use d.setDate(d.getDate() + n) where n is the required number of days to add.

    If you then call getYear(), getMonth() and getDate() again you will find that they’ve all been “corrected” to valid values:

    > d = new Date()
    Wed Aug 29 2012 20:57:12 GMT+0100 (BST)
    > [d.getDate(), d.getMonth() + 1]
    [29, 8]
    > d.setDate(d.getDate() + 10);
    1347134232993
    > [d.getDate(), d.getMonth() + 1]
    [8, 9]
    

    Adding months is not so straightforward, because you need to define what happens when the following month is shorter than the current month – e.g. what date is “one month after 31st January” ?

    Calculating the start of the next month is easy enough, though!

    var now = new Date();
    var start = new Date(now.getFullYear(), now.getMonth(), now.getDate());
    var end   = new Date(now.getFullYear(), now.getMonth(), now.getDate());
    
    if ($('._tomorrow').is(':checked')) {
        start.setDate(now.getDate() + 1);
          end.setDate(now.getDate() + 2);
    } else if ($('._weekend').is(':checked')) {
        start.setDate(now.getDate() + 6 - now.getDay());
          end.setDate(now.getDate() + 8 - now.getDay());
    } else if ($('._nextmonth').is(':checked')) {
        start.setDate(1);
          end.setDate(1);
        start.setMonth(now.getMonth() + 1);
          end.setMonth(now.getMonth() + 2);
    }
    
    var startStr = [start.getMonth() + 1, start.getDate(), start.getFullYear()].join('/');
    var endStr = [end.getMonth() + 1, end.getDate(), end.getFullYear()].join('/');
    

    See http://jsfiddle.net/alnitak/nTSMg/

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

Sidebar

Related Questions

Let me be clear this line of code works right now. I just feel
I have this code right now to get the row value from jquery grid..
Right now, I have this code where $obj_arr maybe contain array and an object.
Right now, I have my code looking like this: SqlTables.java: // Separate file public
I'm trying to make Gzip compression work on xampp, right now this is in
Right now I can use this URL to request a Google Static Maps image
Right, so this is strange. This code works as expected: HTML: <section> Section #1
As of right now I'm using this code below to download files to get
This code below works perfectly for all browsers except IE 7 or 8. <img
I have this code that works half way through jQuery('#checkbox').click(function () { jQuery('.cssBox').animate({height:'+=50px'}, 500);

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.