Saving date in myql -
ax1 - 10.12.2016
This one doesn't work
Код:
new year, m, d, string[20];
getdate(year, m, d);
format(string, 20, "%02d/%02d/%04d", d, m, year);
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `PosX`, `PosY`, `PosZ`, 'RegDate') VALUES ('%e', '%e', '%e', %f, %f, %f, '%e')", playername, pw, ip ,x,y,z, string);
mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
This one does work
Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `PosX`, `PosY`, `PosZ`) VALUES ('%e', '%e', '%e', %f, %f, %f, )", playername, pw, ip ,x,y,z);
mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
Why?
Re: Saving date in myql -
Vince - 10.12.2016
If regdate is a date or datetime column then honestly just use the inbuilt NOW() or UTC_TIMESTAMP() function.
https://dev.mysql.com/doc/refman/5.5..._utc-timestamp
Re: Saving date in myql -
ax1 - 10.12.2016
Quote:
Originally Posted by Vince
|
Can you give an example as to how should i use it? Should I put UTC_TIMESTAMP() before mysql_format?
Re: Saving date in myql -
Konstantinos - 10.12.2016
Set the column as timestamp. Then in VALUES part, you call
NOW() function or even better set a default value to
CURRENT_TIMESTAMP. If you ever want to retrieve when the player registered, execute a query:
pawn Код:
SELECT DATE_FORMAT(RegDate, '%%d/%%m/%%Y %%r') FROM accounts WHERE ...
the registration date is in row index 0 and field index 0 or just set an alias and retrieve it by its column name. You can change the specifiers in
DATE_FORMAT if you want to, more here:
https://dev.mysql.com/doc/refman/5.5...on_date-format
Re: Saving date in myql -
ax1 - 10.12.2016
Quote:
Originally Posted by Konstantinos
Set the column as timestamp. Then in VALUES part, you call NOW() function or even better set a default value to CURRENT_TIMESTAMP. If you ever want to retrieve when the player registered, execute a query:
pawn Код:
SELECT DATE_FORMAT(RegDate, '%%d/%%m/%%Y %%r') FROM accounts WHERE ...
the registration date is in row index 0 and field index 0 or just set an alias and retrieve it by its column name. You can change the specifiers in DATE_FORMAT if you want to, more here: https://dev.mysql.com/doc/refman/5.5...on_date-format
|
I get this
Re: Saving date in myql -
Konstantinos - 10.12.2016
Isn't that the "Length/Values" box? In the next one which is "Default", click on the arrow and should display CURRENT_TIME.
Re: Saving date in myql -
Runn3R - 10.12.2016
You can just set the rows default value to CURRENT_TIMESTAMP()
You are creating a new one (INSERT) not editing it eh..
Re: Saving date in myql -
ax1 - 10.12.2016
Thanks guys, it worked. Also, can I somehow update date?