A little help in saving and loading time with MySQL.
#1

Hey,

I want to save and load registry date/time with just one string var. For that I was wondering that if something like this would work?

When Player Registers;
Код:
mysql_format(SQL_Connection_Var, query, sizeof(query), "UPDATE players SET RegistryDate=FROM_UNIXTIME(%d, '%%d %%m %%Y %%H:%%I') WHERE id=%d LIMIT 1", 
		GetTime(),PlayerInfo[playerid][pID]);
		mysql_tquery(g_SQL, query);
For loading simple way of loading a string.
Reply
#2

https://sampwiki.blast.hk/wiki/Gettime
Reply
#3

Quote:
Originally Posted by itsCody
Посмотреть сообщение
Well I did check that many times, but that won't help me in what i'm doing.
Reply
#4

What datatype is it? It seems like it's datetime in which case you can simply use UTC_TIMESTAMP() to insert the current date and time.
Reply
#5

https://sampforum.blast.hk/showthread.php?tid=609261
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
What datatype is it? It seems like it's datetime in which case you can simply use UTC_TIMESTAMP() to insert the current date and time.
Код:
mysql_format(SQL_Connection_Var, query, sizeof(query), "UPDATE players SET RegistryDate=UTC_TIMESTAMP() WHERE id=%d LIMIT 1", 
		PlayerInfo[playerid][pID]);
		mysql_tquery(g_SQL, query);
btw would this work too?? This one could be later used for unban date etc. And how can I load it in the timestap from the same column.

Код:
mysql_format(SQL_Connection_Var, query, sizeof(query), "UPDATE players SET Var=UTC_TIMESTAMP()+(60*60*%d) WHERE id=%d LIMIT 1", 
		days,PlayerInfo[playerid][pID]);
		mysql_tquery(g_SQL, query);
Reply
#7

I have it as TIMESTAMP and on registering, it inserts NOW() by default (default value is set to "DEFAULT CURRENT_TIMESTAMP" when the table is created).

I do have a different table for bans and I have created an event scheduler (https://sampforum.blast.hk/showthread.php?tid=546630) to be run and automatically delete rows in which the expire time has been passed.

An example:
pawn Код:
"CREATE DEFINER=`root`@`localhost` EVENT `auto_unban` ON SCHEDULE EVERY 1 MINUTE STARTS '2016-06-01 22:21:15' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM bans WHERE expire != 0 AND NOW() >= expire;"
If expire (TIMESTAMP which is by default 0, have disabled sql mode for zero dates) is not 0 for permanent and the current time is greater than the value of "expire" column (which is set to NOW() + interval). When I insert a ban in the table, I do add the days the player will be banned with:
pawn Код:
TIMESTAMPADD(DAY,%i,NOW())
Reply
#8

Yep i'm already using events for that.

But can the dates in format of that UTC_TIMESTAMP(Strings like dd/mm/yy etc) be compared with each other? Or I have to use the simple timestamp(the numeric one only) format for it?

If yes, how?

Код:
TIMESTAMPADD(DAY,%i,NOW())
Ty for this.
Reply
#9

See: http://dev.mysql.com/doc/refman/5.7/...functions.html

PHP код:
UPDATE players SET Var = DATE_ADD(UTC_TIMESTAMP(), INTERVAL %d HOURWHERE id=%
Reply
#10

You may see them through tools such as phpmyAdmin as a string but they are actually saved as numbers. You can add, subtract normal with the appropriate functions: https://dev.mysql.com/doc/refman/5.5...functions.html
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)