getdate in mysql database
#1

Hello guys,

When a player registers I want that the register date is saved in the database.

This is the code I thought would work. Whenever I try it out I get the number 104 on my table. The RegisterDate is defined as an int of 12. I also have the question how you determine your query length that you need. I currently have it at 1000 because I'm not sure what to make it. Can anyone help me with this? I'm quite new at mysql and try to understand everything by experimenting with it.

Код:
new Year, Month, Day, Days;
getdate(Year, Month, Day);

new DB_Query[1000], year, month, day;
getdate(year, month, day);
mysql_format(MYSQL_CONNECT, DB_Query, sizeof(DB_Query), "INSERT INTO `Players` (`Username`, `Password`, `Salt`, `RegisterDate`, `RegisterIP`, `LastIP`, `Admin`, `Developer`, `Helper`)\
VALUES ('%e', '%s', '%e', '%d/%d/%04d', '%e', '%e', '0', '0', '0')", pData[playerid][Username], pData[playerid][Password], pData[playerid][Salt], day, month, year, pData[playerid][RegisterIP], pData[playerid][RegisterIP]);
mysql_tquery(MYSQL_CONNECT, DB_Query, "OnPlayerRegister", "d", playerid);
Reply
#2

INT(12) holds only integer/number not string '%d/%d/%04d' you can use timestamp, change to %d and replace 'day, month, year' part into gettime() then you can select date

pawn Код:
"SELECT FROM_UNIXTIME(`RegisterDate`) AS `RegDate` WHERE `Username` = '%e' LIMIT 1;"
https://dev.mysql.com/doc/refman/5.5..._from-unixtime
Reply
#3

You mean mysql function NOW()?
Reply
#4

This helped me too https://www.w3schools.com/sql/func_curdate.asp
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)