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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:08:28+00:00 2026-06-07T19:08:28+00:00

This is for a system that essentially allows you to set the first date

  • 0

This is for a system that essentially allows you to set the first date for a given event, then to set the recurrence period.

Eg. I set a date for a week from now, 19/07/2012, so I know that I have to put the cat out with the milk. I also set it to be a weekly notification, so in future weeks I want to be notified of the same.

That original date sits in my database, which is fine for week 1, but in week 2 I need to return the date as the original plus 1 week.

On the face of it, that may seem straightforward, but I need to make sure I can account for leap years and different recurrence frequencies (fortnightly, monthly, yearly, whatever).

I’d like to keep this as a javascript implementation – because it’s quicker and I feel probably would require less code than updating dates in the database. Maybe it’s not achievable, any pointers would be excellent.

I think these may be a starting point:

Given a start date , how to calculate number of years till current date in javascript

Given a date, how can I efficiently calculate the next date in a given sequence (weekly, monthly, annually)?

Update, I’ve written the below to return the amount of time to add in each different case, from there I can just use the answer below:

var strDate = $(this).find('.next').text();
            var frequency = $(this).find('.occurs').text();
            var frmDate = getDateObject(strDate);
            var toDate = new Date();

            var days = parseInt(Math.floor((frmDate - toDate) / 86400000));

            if(days < 0) {
                // find out how many WHOLE 'frequencies' have passed
                var weeks = Math.ceil(0 - (days / 7));
                var months = Math.ceil(0 - (monthDiff(toDate,frmDate)));
                var years = Math.ceil(months / 12);
                //alert(days + '/' + weeks + '/' + fortnights + '/' + months + '/' + quarters + '/' + years);

                if(frequency == 'Weekly') { frmDate.add(weeks).weeks(); }
                if(frequency == 'Fortnightly') { frmDate.add(weeks*2).weeks(); }
                if(frequency == 'Monthly') { frmDate.add(months).months(); }
                if(frequency == 'Quarterly') { frmDate.add(months*3).months(); }
                if(frequency == 'Annually') { frmDate.add(years).years(); }

                var newdate = frmDate.toString("dd/MM/yyyy");
                //alert(newdate);

                $(this).find('.next').text(newdate);
            }
  • 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-07T19:08:30+00:00Added an answer on June 7, 2026 at 7:08 pm

    Also, the SQL implementation for this would be using DATEADD:

    http://sql-plsql.blogspot.com/2010/07/dateadd.html

    You don’t have to worry about special dates like leap year and so forth, because most Date functions take care of that.

    Alternatively, you can use the getDate(), getMonth() as the other user suggested.
    var today = new Date();
    today.setDate(today.getDate() + numberOfDaysToAdd);

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

Sidebar

Related Questions

I have set up a configuration system that will grab the configuration from a
I have a system that runs like this: main.exe runs sub.exe runs sub2.exe and
This is for some high level Web/Rest tests of my whole system that are
In a class, I've got a trace method that looks like this: [System.Diagnostics.ConditionalAttribute(Trace)] private
This code: System.out.println(String.format(%f, Math.PI)); System.out.println(Math.PI); produces that result on my computer: 3,141593 3.141592653589793 Why
I have a number of static classes that contain tables like this: using System;
I have a machine control system in Python that currently looks roughly like this
I have a messaging system (very basic) that has a table like this: **MESSAGE_ID**
I'm being passed an object that returns System.Byte[*] when converted to string. This apparently
I got a view that inherits : System.Web.Mvc.ViewPage<IEnumerable<MyProjects.Models.MyAccountWrapper>> In this view I list data

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.