Month day year, etc statistic - 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: Month day year, etc statistic (
/showthread.php?tid=662179)
Month day year, etc statistic -
DarkMythHunter - 25.12.2018
PHP код:
IRCCMD:topplayers(botid, channel[], user[], host[], params[])
{
new _query[180], fetchedName[MAX_PLAYER_NAME], lastseen[40], activity, Cache:results;
results = mysql_query(handle, "SELECT `Username`, `Activity`, `LastLoggedIn` FROM `accounts` ORDER BY `Activity` DESC LIMIT 10");
IRC_GroupSay(gGroupID, channel, "00,12-----[Top 10 monthly active players]-----");
for(new Qr, rows = cache_num_rows(); Qr<rows; Qr++)
{
cache_get_value_name(Qr, "Username", fetchedName);
cache_get_value_name_int(Qr, "Activity", activity);
cache_get_value_name(Qr, "LastLoggedIn", lastseen);
format(_query, sizeof(_query), "\x020,12 #%d\x02 - Username: \x1D%s\x1D Last seen at: \x1D%s\x1D Activity: \x1D%d\x1D minute(s)", Qr+1, fetchedName, lastseen, activity / 60);
IRC_GroupSay(gGroupID, channel, _query);
}
IRC_GroupSay(gGroupID, channel, "00,12-----------------------------------------");
cache_delete(results);
return 1;
}
It currently shows as "minutes" like it divides the time fetched from the database "Activity" which is in seconds, and divide it into 60. What I want is for it to show like: 1 Month, 1 week, 6 days, 1 hour, 13 seconds. Just like that. I'm having problems how to do it, I suppose it needs to use a unix timestamp or idk. Can anyone tell me how?
Re: Month day year, etc statistic -
iorp - 25.12.2018
you need to do some mathematical calculation to convert a timestamp into desired format like
year = timestamp/(365*24*60*60) % 365
month = timestamp/(30*24*60*60) % 30
week = timestamp/(7*24*60*60) % 7
Days = timestamp/(24*60*60) % 24
Hour = timestamp/(60*60) % 24
Minute = timestamp/(60) % 60
Seconds = timestamp % 60