SA-MP Forums Archive
SQL date - 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: SQL date (/showthread.php?tid=598321)



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(mysqlquerysizeof(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 dmy;
getdate(ymd);
mysql_format(mysqlquerysizeof(query),"INSERT INTO `table` (`Date`) VALUES ('%i/%i/%i')"dmy,); 
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 dmy;
getdate(ymd);
mysql_format(mysqlquerysizeof(query),"INSERT INTO `table` (`Date`) VALUES ('%i/%i/%i')"dmy,); 
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(mysqlquerysizeof(query),"INSERT INTO `crimes` (`Name`,`Reason`,`Date`) VALUES ('%e','%e','%i/%i/%i')",GetName(otherplayer),reason,dmy); 
[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(YearMonthDay);
    
gettime(HourMinuteSecond);
    
// Construct the complete date to be added to MySQL for the registration date+time
    
format(Datesizeof(Date), "%04d-%02d-%02d %02d:%02d:%02d"YearMonthDayHourMinuteSecond);

    
// 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_dbQuerysizeof(Query), "INSERT INTO playerdata (Name, Password, RegisterDate, IP) VALUES ('%e', '%s', '%s', '%s')"APlayerData[playerid][Name], APlayerData[playerid][Password], DateAPlayerData[playerid][IP]);
    
mysql_tquery(SQL_dbQuery"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() ...