Generate Random Dates

Generate Random Dates

Master Tag
Tips & Tricks
Created
Oct 14, 2021 03:32 PM
How It Works
Usage
fromTimestamp
timestamp
dateBetween
replaceAll
id
Now()
Round
Year
dateAdd
Web Tags
Formula
Cover
⚠️
Conditions
  1. Random Date: random date between 15 October 1582 and Today
    1. Firstly, find the timestamp() of your start and end dates.
    2. You can do this by creating a temporary date property with desired date.
    3. Then create a formula property with this code: timestamp(prop("Name of Date Property")).
    4. Copy and paste to page to save for later.
    5. formatDate(dateAdd(fromTimestamp(-12219274800000), round(toNumber(replaceAll(id(), "[^0-9]", "")) % (dateBetween(now(), fromTimestamp(-12219274800000), "days") + 1) * 10 / 10), "days"), "LL")
      In this formula, I only needed a timestamp for start date (Oct 15, 1582).
  1. Random Year: random year between 1500 and This Year
    1. add(1500, round(toNumber(replaceAll(id(), "[^0-9]", "")) % (year(now()) - 1500 + 1) * 10 / 10))
  1. Random Day: random day between Monday and Sunday
    1. if(round(toNumber(replaceAll(id(), "[^0-9]", "")) % 7 * 10 / 10) == 0, "Sunday", if(round(toNumber(replaceAll(id(), "[^0-9]", "")) % 7 * 10 / 10) == 1, "Monday", if(round(toNumber(replaceAll(id(), "[^0-9]", "")) % 7 * 10 / 10) == 2, "Tuesday", if(round(toNumber(replaceAll(id(), "[^0-9]", "")) % 7 * 10 / 10) == 3, "Wednesday", if(round(toNumber(replaceAll(id(), "[^0-9]", "")) % 7 * 10 / 10) == 4, "Thursday", if(round(toNumber(replaceAll(id(), "[^0-9]", "")) % 7 * 10 / 10) == 5, "Friday", if(round(toNumber(replaceAll(id(), "[^0-9]", "")) % 7 * 10 / 10) == 6, "Saturday", "")))))))
 
Random