-SOLVED -Display the year but one year ahead

Hi, I have the following code to display the current year but was wondering if it’s possible to display the following year?

$w.onReady(function () {
 const today = new Date();
    $w("#2019date").text = today.getFullYear().toString();
});

Many thanks in advance!

Hi!

Since full year is a number, you can just add 1.

$w("#2019date").text = (today.getFullYear() + 1).toString()

I hope this helps.

Thank you! I had tried to add +1 but had it in the wrong place…

I was wondering how complex it gets if I wanted to add 1 year but subtract 1 day?
The idea being that if a course started on Monday 17th Sept 2018 then the same date for the following year would be Monday 16th Sept 2019

There is a nice example in StackOverflow here:

It uses only JavaScript APIs, so will work in both public and backend code.

The idea is that JavaScript time is in milliseconds, so if you cadd 24 * 60 * 60 * 1000 milliseconds, you will effectively add a day.

When writing backend functions, you can also use momentjs npm module, which makes time arithmetic easier.

Hi Giedrius,

Thank you for the info, I think this may start to get too much for my head, I’ve spent waayy to much time working out other code problems… I’m just wondering if I should make some other date fields in the database to connect to.
I have a switch that changes dates from 2019 to 2020 or vice versa for people wishing to book in advance.
I just had the idea that it would save me lot of time if I only had to adjust a 6 dates per course as apposed to 12!