add days to date

Post Reply
administrator
Site Admin
Posts: 82
Joined: Mon Dec 03, 2018 10:35 am

add days to date

Post by administrator » Thu Feb 08, 2024 10:54 am

To set a date from today like: Today = 08-02-2024 but you need 14 days from now, you can use this OL-Script:

Code: Select all

// Get current date
var date = new Date();

// Add 14 days to current date, change to number of days needed.
date.setDate(date.getDate() + 14);

// Function to format the date as "dd month yyyy"
function formatDate(date) {
  const months = [
    "januari", "februari", "maart", "april", "mei", "juni",
    "juli", "augustus", "september", "oktober", "november", "december"
  ];

  const day = date.getDate();
  const month = months[date.getMonth()];
  const year = date.getFullYear();

  return `${day} ${month} ${year}`;
}

// Get the formatted date
var formattedDate = formatDate(date);


results.html(formattedDate);
Or download this OL-Script:
tilldate.zip
Date = 14 days from now
(1.47 KiB) Downloaded 3633 times
tilldate.zip
Date = 14 days from now
(1.47 KiB) Downloaded 3633 times

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests