Compare two dates and times.. -
Outbreak - 23.04.2009
Hey, is there a way to use "gettime" and "getdate", then save them in a string...
Then later compare them. and check for the difference.
So if its todays date...
23/04/2009 time = 16:03:17 (approx)
then save that, so then it can be compared later when needed..
So take the above date and time... check it against the current date and time, then get the difference..
To make it easier, i'd like to first compare the dates, if they match then compare the times...
If they dont match just clear the saved date and time..
Re: Compare two dates and times.. -
Rimeau - 23.04.2009
Why do you want to save them in a string...?! And not as integers?
Re: Compare two dates and times.. -
ICECOLDKILLAK8 - 23.04.2009
Use
strcmp
Re: Compare two dates and times.. -
Joe Staff - 23.04.2009
I think he's considering a temporary ban function or something.
second=second1-second2;
if(second<0){second+=60;minute1-=1;}
minute=minute1-minute2;
if(minute<0){minute+=60;hour1-=1;}
hour=hour1-hour2;
if(hour<0){hour+=24;day1-=1;}
day=day1-day2;
if(day<0){day+=30;month1-1;} //the 30 depends on the month could be 30, 31, 28, or 29
month=month1-month2;
if(month<0){month+=12;year1-=1;}
year=year1-year2;
Then year,month,day,hour, and minute are set to the difference of time 1 and time 2
Re: Compare two dates and times.. -
Outbreak - 25.04.2009
I dont really want to use too many "if"s
I need to compare them, and check weather or not 30minutes have gone by or not..
If the player logs on within 30mins of leaving the server, the data from the file will be loaded.
If they login after 30mins of leaving the server the file will be deleted.
So i need to check if its been 30mins from the player leaving to reconnecting...
Re: Compare two dates and times.. -
Weirdosport - 25.04.2009
Assuming the server is on the whole time, use gettickcount(), and then work out what 30 minutes is in milliseconds.
Re: Compare two dates and times.. -
Joe Staff - 25.04.2009
Quote:
Originally Posted by Outbreak
I dont really want to use too many "if"s
I need to compare them, and check weather or not 30minutes have gone by or not..
If the player logs on within 30mins of leaving the server, the data from the file will be loaded.
If they login after 30mins of leaving the server the file will be deleted.
So i need to check if its been 30mins from the player leaving to reconnecting...
|
There's really only one other way, and that is to convert days-hours-minute-seconds into a single number (seconds)
Re: Compare two dates and times.. -
Weirdosport - 25.04.2009
Or read the previous response and use gettickcount...
Re: Compare two dates and times.. -
Outbreak - 25.04.2009
I Like the idea of converting it into one number...
The only thing with that is. If the player leaves at 11:45pm and they login again at 12:05am then the date changes...
So im not sure how i can make it work accurately
Re: Compare two dates and times.. -
yom - 26.04.2009
Store the return value of gettime() (without parameters) into a variable then later, call gettime() again and compare to whatever you want in seconds
Example:
pawn Code:
//new variable at top of script
new time;
//set variable
time = gettime();
//later, for compare:
if (gettime() >= time + 30) //30 seconds or more elapsed