Put the date in a variable and time in another variable?

hi, i need to retrieve date and time, to put them in a separated variable…to work than thim them…

Can some body help me please, step by step…?? i don’t see many examples like this…Gdevelop is great but not so many intuitive for me…best regards…Lestroso

This may help

1 Like

have a look at the below, it will put the current time into a variable named time and the current date into a variable named date

1 Like

Sorry i did not ask if you needed the numeric values, if you copy and past the JavaScript below into a JavaScript event it will put put the separate values into the scene variables

hour
minutes
day
month
year

if you edit the script you can change them to whatever you like

// Get the current date and time
const now = new Date();

// Break down the time
const hours = now.getHours(); // Get current hour (0-23)
const minutes = now.getMinutes(); // Get current minutes (0-59)

// Break down the date
const day = now.getDate(); // Get current day of the month (1-31)
const month = now.getMonth() + 1; // Get current month (0-11, so we add 1 to make it 1-12)
const year = now.getFullYear(); // Get current year

// Pass the values to GDevelop variables
runtimeScene.getVariables().get(“hour”).setNumber(hours);
runtimeScene.getVariables().get(“minutes”).setNumber(minutes);
runtimeScene.getVariables().get(“day”).setNumber(day);
runtimeScene.getVariables().get(“month”).setNumber(month);
runtimeScene.getVariables().get(“year”).setNumber(year);

1 Like

thanks a lot for your precious code and answer… this work fine for me …but i have had to create 2 variables to set your demo code…thanks a lot again…Lestroso

1 Like