Alright so currently, to track the day/month/year and weekday im using a singular number value from 1-365. However its not going so well, i’ve been so close but its calculating the days of the months wrong. Btw this is In-Game Time that starts what real world date.
local timeTable = os.date("*t")
local daysInMonths = {31,28,31,30,31,30,31,31,30,31,30,31}
local daysInMonthsConversion = {31,59,90,120,151,181,212,243,273,304,334,365}
game.Lighting.DayStats.Day.Value = timeTable.yday
game.Lighting.DayStats.Year.Value = timeTable.year
game.Lighting.DayStats.WeekDay.Value = timeTable.wday
game.Lighting.DayStats.Month.Value = timeTable.month
while true do
wait()
local daysInYear = 365
local day = game.Lighting.DayStats.Day.Value
local monthPassed = 0
for x,passValue in pairs(daysInMonthsConversion) do
if day > passValue then
monthPassed = monthPassed+1
end
end
local subtract = 0
for x,v in pairs(daysInMonths) do
if x <= monthPassed then
subtract = subtract + v
end
end
game.Lighting.DayStats.Month.Value = monthPassed+1
game.Lighting.DayStats.MonthDay.Value = day-subtract-1
end
Can anyone point me to a resource that might help, and explain please?
I’m not too sure what exactly your code was doing, but I changed up the calculations a bit and got something that works correctly, as far as I can tell. If this isn’t suitable for your needs, let me know and I can try and help find a proper solution.
local timeTable = os.date("*t")
local daysInMonths = {31,28,31,30,31,30,31,31,30,31,30,31}
local daysInMonthsConversion = {31,59,90,120,151,181,212,243,273,304,334,365}
local Day = game.Lighting.DayStats.Day
local Year = game.Lighting.DayStats.Year
local WeekDay = game.Lighting.DayStats.WeekDay
local Month = game.Lighting.DayStats.Month
local MonthDay = game.Lighting.DayStats.MonthDay
Day.Value = timeTable.yday
Year.Value = timeTable.year
WeekDay.Value = timeTable.wday
Month.Value = timeTable.month
while true do
Day.Value += 1
Year.Value = math.floor(Day.Value / 365) + 1
-- Modulo operation to get the correct day of the year and day of the week
local day = Day.Value % 365
local weekDay = day % 7
-- Probably a better way to do mudolo above, set values to their max if they were previously at it
if day == 0 then
day = 365
end
if weekDay == 0 then
weekDay = 7
end
WeekDay.Value = weekDay
-- Iterate through table to get the correct month and monthday values
for i,v in ipairs (daysInMonthsConversion) do
if v >= day then
Month.Value = i
-- MonthDay is just day minus previous dayInMonths value, or just the day if the month is 1
MonthDay.Value = day - (daysInMonthsConversion[i - 1] or 0)
break
end
end
task.wait(5)
end