• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Question about date and time

N

Noba

Guest
So I've looked up the options for checking the date and time, and I sort of get how it all works. One issue I'm having however is how I'd check for a specific hour. Say if I wanted 7 am in the morning, how would I check for this? Is it in milliseconds? And does it reset when the system time reached midnight?
 

Joe Ellis

Member
I think you'd use date_current_datetime(), which gets the exact date time, with everything in, then cancel it down so:

if date_get_hour(date_current_datetime()) = 7

I think this returns the full 24 hours, so probably like on a digital clock it would be 0:00 at midnight, and would be the next day.

But the date_current_datetime() function needs to be called at the exact same time you check the hour, minute, etc. as it's constantly changing as time goes on.
 
F

Frolacosta

Guest
As Joe Ellis said you check it with using the 24 hour numbers. So to check for 7am you would use

Code:
if date_get_hour(date_current_datetime()) = 7 {
 //code
}
If you wanted to check for 7pm you would use
Code:
[CODE]if date_get_hour(date_current_datetime()) = 19 {
 //code
}
[/CODE]

If you want to check for midnight, you would check for a value of 0, so yes the hour numbers you check for do reset at midnight
 
N

Noba

Guest
As Joe Ellis said you check it with using the 24 hour numbers. So to check for 7am you would use

Code:
if date_get_hour(date_current_datetime()) = 7 {
 //code
}
If you wanted to check for 7pm you would use
Code:
[CODE]if date_get_hour(date_current_datetime()) = 19 {
 //code
}
[/CODE]

If you want to check for midnight, you would check for a value of 0, so yes the hour numbers you check for do reset at midnight
Ah really? That makes it much easier! Thank you both! :)
 
Top