Best way to get a month, year, etc... based off a day value?

Hi. I’m using the workspace.DistrubutedGameTime to determine the day, month, and year of a server. Each day is 400 seconds long, and I use the same equation everywhere to determine the current day.

Day equation:

local day = math.floor(workspace.DistrubutedGameTime/400)

--optionally for server scripts I can use the global variable that I created.

Using this day value, I want to get the month, year, day of the month, and weekday name. I already created something for this but it’s very wierd looking and not all that efficient. In my current system, each month is the same length and each month has exactly 4 weeks. I want to make it more like the time system of the real world.

Is there some kind of easy way to do this? To get the month, weekday, etc… from the amount of ingame days that have passed on a server?

1 Like

What you have for the day is great so far. There is not a builtin that would allow for this functionality if that is what you are asking. You would have to use math to determine the month, weekday, week and others.

For the weekdays, the easiest way to go about it would be to create a table with the weekdays in order and find the total days % 7 to index the correct weekday.

local weekdays = {} -- assume its been correctly declared with 7 values
local currentWeekday = (day % 7) + 1 -- Add one because lua tables start indexing at 1
print("The current weekday is", weekdays[currentWeekday])
1 Like

edit: for anyone else who may come across this topic, there actually is a function for this called However you should only run it on the server if you want to use it. I used the workspace.DistributedGameTime as the time input, plus a huge value to get it over 1980 in years. It also has leapyears, daylight saving time, etc… I don’t want to get into the details, it should be sort of obvious once you learn the documentation

1 Like