SQL date -
Squirrel - 10.01.2016
Alright so I made a simple query, but I want to insert date with it. I have created row with "Date" and set Datatype to date, how to recognize what date is it? I mean how to insert the date?
PHP код:
mysql_format(mysql, query, sizeof(query),"INSERT INTO `crimes` (`Name`,`Reason`) VALUES ('%e','%e')",GetName(otherplayer),reason);
So basically how do I use DATATYPE 'date'
Re: SQL date -
itsCody - 10.01.2016
You could try getdate?
https://sampwiki.blast.hk/wiki/Getdate
Re: SQL date -
Squirrel - 10.01.2016
Quote:
Originally Posted by itsCody
|
Yeah could but wouldnt that actually make me use 3 columns in SQL instead of 1?
Re: SQL date -
itsCody - 10.01.2016
No. Change the date column to an varchar and just use
PHP код:
new d, m, y;
getdate(y, m, d);
mysql_format(mysql, query, sizeof(query),"INSERT INTO `table` (`Date`) VALUES ('%i/%i/%i')", d, m, y,);
Depends on how you want to use the date, but that's how I insert the dates on my ban queries, and reports.
Re: SQL date -
Squirrel - 11.01.2016
Quote:
Originally Posted by itsCody
No. Change the date column to an int and just use
PHP код:
new d, m, y;
getdate(y, m, d);
mysql_format(mysql, query, sizeof(query),"INSERT INTO `table` (`Date`) VALUES ('%i/%i/%i')", d, m, y,);
Depends on how you want to use the date, but that's how I insert the dates on my ban queries, and reports.
|
Yeah but im getting some errors in the log
PHP код:
mysql_format(mysql, query, sizeof(query),"INSERT INTO `crimes` (`Name`,`Reason`,`Date`) VALUES ('%e','%e','%i/%i/%i')",GetName(otherplayer),reason,d, m, y);
[php](error #1265) Data truncated for column 'Date' at row 1[php]
Re: SQL date -
itsCody - 11.01.2016
What's the type for your column? I accidentally said change it to an int, but it's actually a varchar. The length of 32 should be enough.
Re: SQL date -
Squirrel - 11.01.2016
haha, yep that one works! Varchar works! +rep
Re: SQL date -
AmigaBlizzard - 11.01.2016
PHP код:
// Get the current date, time
getdate(Year, Month, Day);
gettime(Hour, Minute, Second);
// Construct the complete date to be added to MySQL for the registration date+time
format(Date, sizeof(Date), "%04d-%02d-%02d %02d:%02d:%02d", Year, Month, Day, Hour, Minute, Second);
// Add the player's account to the MySQL database (escape the name only, as there is no need to escape a hashed password)
mysql_format(SQL_db, Query, sizeof(Query), "INSERT INTO playerdata (Name, Password, RegisterDate, IP) VALUES ('%e', '%s', '%s', '%s')", APlayerData[playerid][Name], APlayerData[playerid][Password], Date, APlayerData[playerid][IP]);
mysql_tquery(SQL_db, Query, "Player_OnAccountCreate", "i", playerid);
Some code from my script which uses "date" datatype in sql.
Re: SQL date -
AmigaBlizzard - 11.01.2016
double post, sorry
Re: SQL date -
Runn3R - 11.01.2016
Or you can just use the mysql NOW() or DATETIME() ...