PDA

View Full Version : Time difference


Backstabnoob
06-12-2010, 09:58
Hey. I want to know, if I have a time like:
2010-05-27 16:11:35

How can I check, if three minutes passed from that time? Like

time is 2010-05-27 16:11:35
new newtime[x]
get_time(newtime, xxx)

if((newtime - time) > 3)
passed


but I need an exact example, cause I do not know.
Thanks in advance.

Bugsy
06-12-2010, 10:07
Are you able to use any other method for your storing your times? It can be done using a string time format like that but it will take more work. It would be easier if you stored the times in unix-time format (timestamp). You can easily determine exact difference (down to seconds) in 2 times with this.

http://forums.alliedmods.net/showthread.php?t=91915

Backstabnoob
06-12-2010, 10:30
Yeah, I can do it with timestamp, just couldn't find that.

Can you show me an example of how to get the difference?

Bugsy
06-12-2010, 10:37
Yeah, I can do it with timestamp, just couldn't find that.

Can you show me an example of how to get the difference?

All you have to do is subtract one time from the other then divide by X to determine the difference in years, months, days, hours, minutes, seconds or w\e.

Use get_systime() in your plugin to get the current unix time.

Current time = 1276338840
5 hours from now = 1276356840

1276356840 - 1276338840 = 18000

MinuteSeconds = 60
HourSeconds = 3600
DaySeconds = 86400

18000 / 3600 = 5