Saving date in myql
#1

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?
Reply
#2

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
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
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
Can you give an example as to how should i use it? Should I put UTC_TIMESTAMP() before mysql_format?
Reply
#4

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
Reply
#5

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
Reply
#6

Isn't that the "Length/Values" box? In the next one which is "Default", click on the arrow and should display CURRENT_TIME.
Reply
#7

You can just set the rows default value to CURRENT_TIMESTAMP()



You are creating a new one (INSERT) not editing it eh..
Reply
#8

Thanks guys, it worked. Also, can I somehow update date?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)