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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:07:57+00:00 2026-06-12T21:07:57+00:00

I am trying to calculate a date from a start date and number of

  • 0

I am trying to calculate a date from a start date and number of days, so basicly add the number of days to a start date and get an end date. The issue is I get some strange results, but only on one date, I have been a few days now trying to figure this one out.

The function is:

CallculateDateFromDays = function(startDate, days) {
var policy_start_date_array = startDate.split("-");
var policy_start_date = new Date(policy_start_date_array[2], policy_start_date_array[1]-1, policy_start_date_array[0]);
var policy_start_date_add = new Date(policy_start_date.getTime() + ((days-1) * 24 * 60 * 60 * 1000));
var dateString = ("0" + (policy_start_date_add.getDate())).slice(-2) + "-" + ("0" + (policy_start_date_add.getMonth()+1)).slice(-2) + "-" + policy_start_date_add.getFullYear();
return dateString;}

The thing is it works until I use the date “28-10-2012” it gives me back the same date even if I add 2 days.

Any ideas, I am stumped.

  • 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-12T21:07:58+00:00Added an answer on June 12, 2026 at 9:07 pm

    Likely your local timezone changes because of the end of the daylight saving time.

    > new Date(2012, 9, 28)
    Sun Oct 28 2012 00:00:00 GMT+0200
    > // 48 hours later:
    > new Date(new Date(2012, 9, 28) + 2 * 24 * 60 * 60 * 1000)
    Mon Oct 29 2012 23:00:00 GMT+0100
    

    Always use the UTC methods!

    BTW, adding days is much more easier with setDate, which also works around timezone issues:

    function calculateDateFromDays(startDate, days) {
        var datestrings = startDate.split("-"),
            date = new Date(+datestrings[2], datestrings[1]-1, +datestrings[0]);
        date.setDate(date.getDate() + days);
        return [("0" + date.getDate()).slice(-2), ("0" + (date.getMonth()+1)).slice(-2), date.getFullYear()].join("-");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to calculate the number of days offset one date is from
I'm trying to calculate time blocks from given date range. Here's my attempt: <?php
i'm trying to use the class DateTime (php>=5.3) to calculate difference from 2 date.
Am trying to calculate the number of rows in a table depending on a
I am trying to calculate number of users, cumulatively for the dellstore2 database. Looking
I'm trying to calculate the time it takes to receive all data from a
I am trying to calculate difference between two date strings both of which are
I am trying to calculate the fiscal year from this following code. But I
I'm trying to calculate the difference between 2 dates, the current date and the
Trying to get a simple COUNT from a table that takes a couple of

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.