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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:05:51+00:00 2026-06-15T23:05:51+00:00

For the following code, $(function() { a = new Date(2008-1-2); monthDiff = function(now, then)

  • 0

For the following code,

$(function() {
    a = new Date("2008-1-2");

    monthDiff = function(now, then) {
        var months;
        months = (now.getFullYear() - then.getFullYear()) * 12;
        months -= then.getMonth() + 1;
        months += now.getMonth();
        return months;
    };

    intervalToDate = function(interval, start, unit) {
        {
            return {
                day: function() {return new Date(start.getTime() + (interval*24*60*60*1000)); },
                week: function() {return new Date(start.getTime() + (interval*7*24*60*60*1000)); },
                month: function() {
                    // the result value below will not return a date object when running (only an object), what is weird is in the debug console, using the line below will totally return a date object.
                    var result = new Date(start.getTime() + interval*4*7*24*60*60*1000);
                    while (monthDiff(result, start) !== interval) {
                        result += 24*60*60*1000;
                    }
                    return result;
                } ,
                year: function() {
                    return start.getFullYear() + interval;
                }
            }[unit]();
        }
    };

    console.log(intervalToDate(20, a, "day"));
    console.log(intervalToDate(20, a, "week"));
    console.log(intervalToDate(20, a, "month"));
    console.log(intervalToDate(20, a, "year"));
})

this line:

month: function() {
                        // the result value below will not return a date object when running (only an object), what is weird is in the debug console, using the line below will totally return a date object.
                        var result = new Date(start.getTime() + interval*4*7*24*60*60*1000);

result will be correctly returned in the debug console. But on running, somehow it is no longer a date object so I ran into the “no method error” when I try to call getFullYear function on it.

  • 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-15T23:05:52+00:00Added an answer on June 15, 2026 at 11:05 pm

    You are additioning and integer value result += 24*60*60*1000; to the date object, you must use the date methods to adding time and not just doing a simple addition.

    Example :

    result.setMilliseconds(result.getMilliseconds() + (24*60*60*1000));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple instances of the following code. var start_time = new Date().getTime(); setTimeout(function
I have the following code: $(function () { var thedate = /Date(1198908717056)/; var thedate2
I'm trying to create a new function in SQL with the following code: CREATE
I am using the following code function xhi(aax) { var aby=document.getElementById(aax); aby.style.bottom=(parseInt(aby.style.bottom)+(screen.height-42)/10)+'px'; if(parseInt(aby.style.bottom)<(screen.height-42))setTimeout('xhi('+aax+')',25); }
I have the following code: function show(){ var a=document.getElementById('somediv').style.display; a=block; } The above code
I have an URL loader with the following code: public function getUploadURL():void { var
I am using the following code... var Graphs:Array = new Array(contentMain.graph1, contentMain.graph2, contentMain.graph3, contentMain.graph4,
I have the following code for selecting a date which I then want to
I have following code: function SetStartDateIfNull(date, range_id) { if (date || isEmpty(date)) { switch
Following code is intended to restrict selection of today's date in datepicker. jQuery(function ()

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.