Time between dates
#1

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
Reply
#2

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.
Reply
#3

How convert it into time stamp?
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)