How To Check The Current Month? and see if the month is greater than 11?

i want check the current month, and see if the month is greater than 11
so i can do automatic christmas event :christmas_tree:

example:
if i get the current month number
and if is greater than 11
then christmas event will start.


btw, i’am releasing a full customizable loading screen soon :slightly_smiling_face:

1 Like

You can use os.date() or DateTime.

  • Example with DateTime (UTC):
local utcMonth = DateTime.now():FormatUniversalTime("M", "en-us")
print(utcMonth) --> 12 (string!)
3 Likes

if i use:

local utcMonth = DateTime.now():FormatUniversalTime("M", "en-us")
if utcMonth > 11 then
	-- event goes here
end

it will work?

Cant you just check if it is the month β€œ12” and not if its greater than 11?

um, i didnt thinked about that.

but if i use

local utcMonth = DateTime.now():FormatUniversalTime("M", "en-us")
if utcMonth == 12 then
	-- event goes here
end

i think it will work

anyway, thanks @fellow_meerkat and @butterpilot123

That is not going to work because token M returns a number representation and (I should have mentioned) in form of a string.

local utcMonth = DateTime.now():FormatUniversalTime("M", "en-us")
print(tonumber(utcMonth) == 12) --> true
local utcMonth = DateTime.now():FormatUniversalTime("MMMM", "en-us")
print(utcMonth == "December") --> true

Good luck!

Edit.

@serverxside no problem.

Just another reminder, utcMonth isn’t equal to 12, but tonumber(utcMonth) == 12 or utcMonth == tostring(12) or utcMonth == "12".

i edited cuz i just saw that printed 12 and not december LOL

Tysm Bro, You Are A Lifesaver! :heart:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.