Register Date
#1

Hi, I want help with my register date.
Well, The register date is inserted into the database normally, all of the date appears, like 25/05/2015.

But when I test it in a command in game, Only the year appears.

My code:
pawn Код:
COMMAND:regdate(playerid, params[])
{
        new rstring[120];
        format(rstring, sizeof(rstring), "Your register date is %d", pInfo[playerid][RegisteredOn]);
        SendClientMessage(playerid, -1, rstring);
        return 1;
}

The INSERT INTO query:
pawn Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX` ,`PosY`, `PosZ`, `Score`, `Infections`, `RegisteredOn`, `Kills`, `Deaths`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0, 0, 0, NOW(), 0, 0)", Name[playerid], pInfo[playerid][Password], IP[playerid]);
                        //Now let's create a new row and insert player's information in it
                        mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
Reply
#2

You must use the string specifier. Not everything with a number in it can be formatted as a number. I would also suggest looking at Unix timestamps. There's a tutorial on these forums somewhere.
Reply
#3

I have the same problem, to save time and threads, I am posting here.
Vince, Can you give example?
Reply
#4

https://dev.mysql.com/doc/refman/5.5...l#function_now
https://dev.mysql.com/doc/refman/5.5...on_date-format

The type of the field "Timestamp" and set it default value as define NOW(). When registering, it will insert the current timestamp itself. When loading use DATE_FORMAT(field_name, format_here)

The formats can be found in the link above.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
https://dev.mysql.com/doc/refman/5.5...l#function_now
https://dev.mysql.com/doc/refman/5.5...on_date-format

The type of the field "Timestamp" and set it default value as define NOW(). When registering, it will insert the current timestamp itself. When loading use DATE_FORMAT(field_name, format_here)

The formats can be found in the link above.
I changed the format into TIMESTAMP in MySQL, I don't understand what do you mean by
Quote:

When loading use DATE_FORMAT(field_name, format_here)
Reply
#6

DATE_FORMAT can be used in queries to select the date and time with a format you apply. For example:
PHP код:
"SELECT DATE_FORMAT(register_date,'%W, %e %M %Y %r') AS date_time FROM players WHERE Name='Maro06';" 
That would return (let's say register_date has the timestamp of few seconds ago): Monday, 25 May 2015 06:57:35 PM

Keep in mind that you'll have to use % sign twice in format or mysql_format functions (PAWN).
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
DATE_FORMAT can be used in queries to select the date and time with a format you apply. For example:
PHP код:
"SELECT DATE_FORMAT(register_date,'%W, %e %M %Y %r') AS date_time FROM players WHERE Name='Maro06';" 
That would return (let's say register_date has the timestamp of few seconds ago): Monday, 25 May 2015 06:57:35 PM

Keep in mind that you'll have to use % sign twice in format or mysql_format functions (PAWN).
I am sorry but I am really confused.

Can someone tell me where to put this and how?
Reply
#8

DATE_FORMAT is optional. The reason I mentioned it is because in my country and most countries, the date/time formats differ.

You can still load the registered date field (which is saved as TIMESTAMP) as a string with cache_get_row function. It's just that the format will be YEAR-MONTH-DAY HOURS:MINUTES:SECONDS
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
DATE_FORMAT is optional. The reason I mentioned it is because in my country and most countries, the date/time formats differ.

You can still load the registered date field (which is saved as TIMESTAMP) as a string with cache_get_row function. It's just that the format will be YEAR-MONTH-DAY HOURS:MINUTES:SECONDS
Can you just edit the codes in the thread and ill understand?
Reply
#10

Quote:
Originally Posted by Maro06
Посмотреть сообщение
Can you just edit the codes in the thread and ill understand?
Just load the player's data including the RegisteredOn or however that field of yours is named and store it to your variable using cache_get_row function (it's pretty much the same way you load any data).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)