+1 vote

I have two variables:

var month :int = null
var day :int = null

Now in the _ready() function I want to set the month and day variable to the real month and day.

For example today is the 09.11.2020 and today month should be set to 11 and day should be set to 9.

Thanks for answers!

in Engine by (376 points)

1 Answer

+1 vote
Best answer

You're looking for OS.get_datetime(). That returns a dictionary containing a bunch of date/time components.

Something like this should work:

func _ready():
    var time = OS.get_datetime()
    var day = time["day"]
    var month = time["month"]
    print("Month: %s, Day: %s" % [month, day])

Output (for today):

Month: 11, Day: 9

See the docs for details...


by (16,810 points)
selected by

Thanks a lot, exactly what I was looking for

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.