Time between dates - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Time between dates (
/showthread.php?tid=605443)
Time between dates -
ScIrUsna - 19.04.2016
Hi,
I have two dates:
2016/04/19 12:52
and
2016/04/19 13:50
It's just example dates and it's strings. How to calculate difference in minutes? that here is 58 min difference
Re: Time between dates -
Crayder - 19.04.2016
First use sscanf to parse the strings.
sscanf(datetime1, "p</:>iiiii", y, m, d, h, m)
sscanf(datetime2, "p</:>iiiii", y, m, d, h, m)
Then determine the time stamp of each from the given times. Subtract the time stamp. Boom, there you go, the new time stamp is your answer. Just convert it back to time and date.
I'd provide more code but I'm on my phone at the moment.
Re: Time between dates -
ScIrUsna - 19.04.2016
How convert it into time stamp?
Re: Time between dates -
Crayder - 19.04.2016
I already made a library that'll work for this:
https://github.com/Crayder/Time-Conv.../timestamp.inc
pawn Код:
new ts1, ts2, ts;
// Get the time from each string
sscanf(datetime1, "p</:>iiiiii", y1, m1, d1, h1, mi1, s1);
sscanf(datetime2, "p</:>iiiiii", y2, m2, d2, h2, mi2, s1);
// Convert the times to timestamps
datetime2stamp(ts1, y1, m1, d1, h1, mi1, s1);
datetime2stamp(ts2, y2, m2, d2, h2, mi2, s2);
// Get the timestamp difference
ts = (ts2 > ts1 ? ts2 - ts1 : ts1 > ts2 ? ts1 - ts2 : 0);
// Get the time difference from the timestamp
TimeInSeconds(ts, y, m, d, h, mi, s); // This is the answer