SQL date
#1

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

You could try getdate?
https://sampwiki.blast.hk/wiki/Getdate
Reply
#3

Quote:
Originally Posted by itsCody
Посмотреть сообщение
Yeah could but wouldnt that actually make me use 3 columns in SQL instead of 1?
Reply
#4

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

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

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

haha, yep that one works! Varchar works! +rep
Reply
#8

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.
Reply
#9

double post, sorry
Reply
#10

Or you can just use the mysql NOW() or DATETIME() ...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)