Registering Date - gettime()
#1

Hi, so I was fedup of the old way which isn't solved yet and I am trying a new way, alright so, what happens now is that it appears like
pawn Код:
1432606679
I know this is normal because they are the seconds counted since blablabla, well yeah so my question is, can someone show me how to convert it into date? yyyy/mm/dd or yyyy/m/d

Some of my code:
pawn Код:
enum PDATA //We name our enumerator as PDATA (which stands for PlayerDATA). You can name it however you want.
{
    ID, //Will be used later to store player's ID from database so we can use it anywhere later
    Password[129], //We will load player's password into this varible from database
    Admin, //We will load player's admin level from database into this variable so we can use it anywhere later.
    VIP, //We will load player's VIP level from database into this variable so we can use it anywhere later.
    Money, //We will load player's money from database into this variable so we can use it anywhere later.
    Float:posX, //We will load player's X position from database into this variable so we can use it anywhere later.
    Float:posY, //We will load player's Y position from database into this variable so we can use it anywhere later.
    Float:posZ, //We will load player's Z from database into this variable so we can use it anywhere later.
    Score,
    Infections,
    RegisteredOn[6],
    Kills,
    Deaths,
    Reg_Time[16]

}
pawn Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX` ,`PosY`, `PosZ`, `Score`, `Infections`, `RegisteredOn`, `Kills`, `Deaths`, `Reg_Time`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0, 0, 0, NOW(), 0, 0, '%d')", Name[playerid], pInfo[playerid][Password], IP[playerid], gettime());
pawn Код:
pInfo[playerid][Reg_Time] = cache_get_field_content_int(0, "Reg_Time");
pawn Код:
COMMAND:regdate(playerid, params[])
{
    new rstring[120];
    format(rstring, sizeof(rstring), "Your register date is %s", pInfo[playerid][Reg_Time]);
    SendClientMessage(playerid, -1, rstring);
    return 1;
}
Oh, by the way, the command now doesnt work at all. it just shows your register date is, tho, the number I posted in the top, is in the localhost.
Thanks for whoever helps!
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=347605
Reply
#3

Quote:
Originally Posted by Pottus
Посмотреть сообщение
I have already checked this, wondered about defining new variables for year, month, day, hour, minute, second, but was confused where would I put the stock.
Reply
#4

pawn Код:
new date[64], d, m, y;
gettime(d, m, y);
format(date, sizeof(date), "%02d/%02d/%02d", d, m, y);
INI_WriteString(file, "Date", date);
Reply
#5

Simply use MySQL's FROM_UNIXTIME() function to fetch the result as string directly when you need it, that's probably the best way.

https://dev.mysql.com/doc/refman/5.1..._from-unixtime
Reply
#6

Quote:
Originally Posted by UltraScripter
Посмотреть сообщение
pawn Код:
new date[64], d, m, y;
gettime(d, m, y);
format(date, sizeof(date), "%02d/%02d/%02d", d, m, y);
INI_WriteString(file, "Date", date);
This doesn't work.
pawn Код:
new query[1020];
            new date[64], d, m, y;
            gettime(d, m, y);
            format(date, sizeof(date), "%02d/%02d/%02d", d, m, y);
            WP_Hash(pInfo[playerid][Password], 129, inputtext); //hashing inputtext
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX` ,`PosY`, `PosZ`, `Score`, `Infections`, `RegisteredOn`, `Kills`, `Deaths`, `Reg_Time`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0, 0, 0, NOW(), 0, 0, '%d')", Name[playerid], pInfo[playerid][Password], IP[playerid], date);
I have tried saving the Reg_Time as %d and %s, but yeah, when it was %s, it appear as 12, if %d it appeared like 49.


@Vince, would you please show an example?
Reply
#7

Код:
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP())

Result: "2015-05-26 12:52:42"
You can specify format which you want.

Код:
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(), "%Y/%m/%d")

Result: "2015/05/26"
Where is UNIX_TIMESTAMP() put column name.
Reply
#8

I am not that awesome in time/mysql thingys.

Thats what I have done now,

pawn Код:
COMMAND:regdate(playerid, params[])
{
    new lolok = mysql_query(mysql, "SELECT FROM_UNIXTIME(Reg_Time, %Y/%m/%d");
   
    new rstring[120];
    format(rstring, sizeof(rstring), "Your register date is %s", lolok);
    SendClientMessage(playerid, -1, rstring);
    return 1;
}
The command still doesnt show anything and, theres a warning of mismatch in mysql_query line.

I am sorry, I am just not that awesome when it comes into time/mysql thingys.
Reply
#9

So you use MySQL, but you can't operate simple queries, weird. Look for examples how to store strings, look in your login code, there are functions for storing data.
Reply
#10

Quote:
Originally Posted by ball
Посмотреть сообщение
So you use MySQL, but you can't operate simple queries, weird. Look for examples how to store strings, look in your login code, there are functions for storing data.
It is not that weird, I never understood time thingys, for MySQL, I am somehow not bad, still learning from tutorials so yeah.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)