SA-MP Forums Archive
getdate in mysql database - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: getdate in mysql database (/showthread.php?tid=632473)



getdate in mysql database - 7daan71 - 14.04.2017

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);



Re: getdate in mysql database - Jefff - 14.04.2017

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


Re: getdate in mysql database - DRIFT_HUNTER - 14.04.2017

You mean mysql function NOW()?


Re: getdate in mysql database - GangstaSunny. - 14.04.2017

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