Month day year, etc statistic
#1

PHP код:
IRCCMD:topplayers(botidchannel[], user[], host[], params[])
{
    new 
_query[180], fetchedName[MAX_PLAYER_NAME], lastseen[40], activityCache:results;
    
results mysql_query(handle"SELECT `Username`, `Activity`, `LastLoggedIn` FROM `accounts` ORDER BY `Activity` DESC LIMIT 10");
    
IRC_GroupSay(gGroupIDchannel"00,12-----[Top 10 monthly active players]-----");
    for(new 
Qrrows cache_num_rows(); Qr<rowsQr++)
    {
        
cache_get_value_name(Qr"Username"fetchedName);
        
cache_get_value_name_int(Qr"Activity"activity);
        
cache_get_value_name(Qr"LastLoggedIn"lastseen);
        
format(_querysizeof(_query), "\x020,12 #%d\x02 - Username: \x1D%s\x1D     Last seen at: \x1D%s\x1D     Activity: \x1D%d\x1D minute(s)"Qr+1fetchedNamelastseenactivity 60);
        
IRC_GroupSay(gGroupIDchannel_query);
    }
    
IRC_GroupSay(gGroupIDchannel"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?
Reply
#2

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)