new y,m,d,h,i;
new y2,m2,d2,h2,i2;
new FullDate[12],FullDate2[12],DATE2[12],TIME2[8]; // FullDate(2) - "YYYYMMDDHHII" ; DATE2 - "YYYY-MM-DD"; TIME2 - "HH:II";
new DateINT,DateINT2; // DateINT(2) - strval(FullDate(2))
getdate(y,m,d);
gettime(h,i);
format(FullDate,12,"%d%02d%02d%02i%02i",y,m,d,h,i); // This will be date without any other symbols (not YYYY-MM-DD, HH:II , but YYYYMMDDHHII)
DateINT = strval(FullDate); // Should return FullDate in integer*..
sscanf("2010-01-01, 12:00","p,ss",DATE2,TIME2); // Splits 2010-01-01, 12:00 >> to 2010-01-01 and 12:00
sscanf(DATE2,"p-ddd",y2,m2,d2); // Splits 2010-01-01 to 2010 01 01
sscanf(TIME2,"p:dd",h2,i2); // Splits 12:00 to 12 00
format(FullDate2,12,"%d%02d%02d%02i%02i",y2,m2,d2,h2,i2); // YYYYMMDDHHII - this is date from file
DateINT2 = strval(FullDate2); // This SHOULD return FullDate2 in integer*..
printf("FullDate: %s , FullDate2: %s , DateINT: %d , DateINT2: %d",FullDate,FullDate2,DateINT,DateINT2); //DEBUG *
[19:12:32] FullDate: 201001061912 , FullDate2: 201001061822 , DateINT: -862401000 , DateINT2: -862401090 |
Originally Posted by bogeyman_EST
Do you need to do the second sscanfs? You could remove them and just set the int to 201001011200, unless it actually has a function that gets the date from somewhere.
Secondly try adding prints to all of the lines, so you could better work out the problem |
Originally Posted by MaVe;
I believe strval wraps to undefined values when the number gets bigger than the maximum value of a 32bit integer (signed 2147483647, unsigned 4294967295)
|
Originally Posted by SiJ
Would this: 201001061912 number work in strval?
|
Originally Posted by MaVe;
Quote:
|
Originally Posted by SiJ
But maybe there's an easier way than this to check difference between two dates?
|
new DB:db = db_open("tmp.db");
if(db) {
new string[80];
format(string, sizeof(string), "SELECT ifnull(julianday('%s', 'utc') - julianday('now'),'')", date);
new DBResult:result = db_query(db, string);
if(db_num_rows(result)) {
db_get_field(result, 0, string, sizeof(string));
if(string[0]) {
printf("Time difference: %s days", string);
} else {
print("Invalid date");
}
}
db_free_result(result);
db_close(db);
} else {
print("Unable to open database");
}
stock ReturnTimeStamp()
{
new datetime[30],
year, month, day,
hour, minute, second;
getdate(year, month, day);
gettime(hour, minute, second);
format(datetime, sizeof(datetime), "%04i-%02i-%02i %02i:%02i:%02i", year, month, day, hour, minute, second);
return datetime;
}
public OnRconCommand(cmd[])
{
if(strcmp(cmd, "test", true) == 0) {
static time;
if(!time) {
time = gettime();
print("Time stored");
} else {
printf("Time passed: %i seconds", gettime() - time);
time = gettime();
}
return 1;
}
return 0;
}