Using time and dates

Is is possible to use time and dates to choose which timeline is started ?
For example, if the user runs an experience before May, 20th, use timeline A if it is after this date, use timeline B.

Thanks for help me!

1 Like

Hi, did u manage to do it?

The FPS counter George just posted uses a function I hadn’t seen before: Date(). I’m guessing from his usage that it’s the standard Javascripty one: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

… so you should be able to do something like:

let m=new Date().getMonth(); // note: jan = 0
let d=new Date().getDate();
if (( m > 3 ) && ( d > 19 )) {
    // it's after April and it's after the 19th, so we must be on May 20 or later
    ...

untested, may contain nuts

Shameful edit: ha - yes, I’ll leave my stinky code there for all to see, but of course that if statement is wrong. It’ll only trigger from May on, but only after the 19th of each month too. I’ll leave correcting it as a fun exercise. That’s my excuse and I’m sticking with it

I just shared this with someone else. I used this site Date() constructor

This was my code from my Sipsmith age verification code I used.

parent.on(“pointerdown”, (e) => {
let year = symbol.nodes.Year_Script.YearInfo; // data from scroll list
let month = symbol.nodes.Month_Script.MonthInfo // data from scroll list
let day = symbol.nodes.Date_Script.DateInfo // data from scroll list
let date: Date = new Date();

date.setDate(day);
date.setMonth(month);
date.setFullYear(year);

console.log("Date = " + date);
console.log("Year = " + date.getFullYear());
console.log("Date = " + date.getDate());
console.log("Month = " + date.getMonth());
console.log("Day = " + date.getDay());

//Age Calculate as year, month,days
var myresult = ageFromDateOfBirthday(date);
console.log (myresult);

if (myresult > 18){
symbol.emit(“Birthday:Pass”);
} else {
symbol.emit(“Birthday:Fail”);
}

});

function ageFromDateOfBirthday(dateOfBirth: any) {
const today = new Date();
const birthDate = new Date(dateOfBirth);
let age = today.getFullYear() - birthDate.getFullYear();
const m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age–;
}
return age;
}

Hope it helps
Steve