Unixtimestamp to Readable Date (Days)
#2

I use the timec function for bans. Here's an example, I use a slightly modified version of it so I only return the days left.

pawn Код:
format(query,sizeof(query),"SELECT * FROM `bans` WHERE `owner` = '%s' OR `ip` = '%s' AND`time` > '%d'",GetName(playerid),realIP[playerid],gettime());
    result = db_query(database,query);
    if(db_num_rows(result))
    {
        new id,name[24],ip[16];
        db_get_field_assoc(result,"id",ip,sizeof(ip)); id = strval(ip);
        db_get_field_assoc(result,"owner",name,sizeof(name));
        db_get_field_assoc(result,"ip",ip,sizeof(ip));
        db_get_field_assoc(result,"reason",reason,sizeof(reason));
        db_get_field_assoc(result,"time",string,sizeof(string)); time = strval(string);
        format(string,sizeof(string),"You're banned.\n\nBan ID: %d\nBanned name: %s\nBanned IP: %s\nBan expires: %s",id,name,ip,timec(time));
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Banned..",string,"Close","");
        KickEx(playerid);
        return db_free_result(result);
    }

stock timec(timestamp,compare = -1)
{
    if (compare == -1)
    {
        compare = gettime();
    }
    new n,Float:d = (timestamp > compare) ? timestamp - compare : compare - timestamp,returnstr[32];
    if (d < 60)
    {
        format(returnstr,sizeof(returnstr),"< 1 minute");
        return returnstr;
    }
    else if (d < 3600)
    { // 3600 = 1 hour
        n = floatround(floatdiv(d,60.0),floatround_floor);
        format(returnstr,sizeof(returnstr),"minute");
    }
    else if (d < 86400)
    { // 86400 = 1 day
        n = floatround(floatdiv(d,3600.0),floatround_floor);
        format(returnstr,sizeof(returnstr),"hour");
    }
    else
    { // 2592000 = 1 month
        n = floatround(floatdiv(d,86400.0),floatround_floor);
        format(returnstr,sizeof(returnstr),"day");
    }
    if (n == 1)
    {
        format(returnstr,sizeof(returnstr),"1 %s",returnstr);
    }
    else
    {
        format(returnstr,sizeof(returnstr),"%d %ss",n,returnstr);
    }
    return returnstr;
}
In your case, you could use something like:


pawn Код:
CMD:vip(playerid,params[])
{
    new vip = GetPVarInt(playerid,"VIP"),string[124];
    if(vip < gettime()) format(string,sizeof(string),"You're not a vip.");
    else format(string,sizeof(string),"You're vip for the next %s",timec(vip));
    SendClientMessage(playerid,-1,string);
    return 1;
}
Reply


Messages In This Thread
Unixtimestamp to Readable Date (Days) - by JaKe Elite - 06.10.2013, 11:57
Re: Unixtimestamp to Readable Date (Days) - by xXShadowXx - 06.10.2013, 12:24
Re: Unixtimestamp to Readable Date (Days) - by JaKe Elite - 07.10.2013, 10:02
Re: Unixtimestamp to Readable Date (Days) - by JaKe Elite - 07.10.2013, 10:54
Re: Unixtimestamp to Readable Date (Days) - by JaKe Elite - 19.10.2013, 04:37
Re: Unixtimestamp to Readable Date (Days) - by JaKe Elite - 02.08.2016, 09:08
Re: Unixtimestamp to Readable Date (Days) - by Vince - 02.08.2016, 09:39
Re: Unixtimestamp to Readable Date (Days) - by JaKe Elite - 02.08.2016, 09:45
Re: Unixtimestamp to Readable Date (Days) - by PrO.GameR - 02.08.2016, 12:30
Re: Unixtimestamp to Readable Date (Days) - by JaKe Elite - 03.08.2016, 09:49

Forum Jump:


Users browsing this thread: 1 Guest(s)