SA-MP Forums Archive
Minor MySQL question. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Minor MySQL question. (/showthread.php?tid=205495)



Minor MySQL question. - _rAped - 01.01.2011

Well.. I have done this before with PHP, just can't remember how I did it.

I have a tables called bans, where I have something called date. This is the date the player is going to be unbanned. How can I check on login if that date has past?

I remember a php function called date_diff or something, anything alike in pawn or do I have to make som magic with MySQL queries?


Re: Minor MySQL question. - Grim_ - 01.01.2011

You can do it either way really. Just compare the data you are retrieving from the database to the current date in the query. Vice versa, you could do it after you retrieve the query and compare the dates.


Re: Minor MySQL question. - _rAped - 01.01.2011

Quote:
Originally Posted by Grim_
Посмотреть сообщение
You can do it either way really. Just compare the data you are retrieving from the database to the current date in the query. Vice versa, you could do it after you retrieve the query and compare the dates.
Well wouldn't that be complicated if the date has passed? Can't really use if(date1 < date2).


Re: Minor MySQL question. - Sergei - 01.01.2011

I'd convert date using UNIX_TIMESTAMP() and compare it with value of gettime.


Re: Minor MySQL question. - _rAped - 01.01.2011

Quote:
Originally Posted by Sergei
Посмотреть сообщение
I'd convert date using UNIX_TIMESTAMP() and compare it with value of gettime.
Yeah that's how I did it with PHP just using date_diff, should I run a 'if' now then?


Re: Minor MySQL question. - DVDK - 01.01.2011

You can do it multiple ways, like you can use 3 arrays from day month and year, or you can use 1 array for the amount of seconds from 1970 = gettime();


Re: Minor MySQL question. - Sergei - 01.01.2011

Код:
SELECT UNIX_TIMESTAMP(datefield) FROM bans WHERE ....

if(gettime() > mysql_fetch_int()) => expired



Re: Minor MySQL question. - _rAped - 01.01.2011

Quote:
Originally Posted by Sergei
Посмотреть сообщение
Код:
SELECT UNIX_TIMESTAMP(datefield) FROM bans WHERE ....

if(gettime() > mysql_fetch_int()) => expired
Lol just noticed something weird when inserting, I'm inserting, I use NOW(). Returns
Quote:

2011-01-01 00:00:01

probably the server watch?


Re: Minor MySQL question. - Sergei - 01.01.2011

You can use CURRENT_TIMESTAMP as default value of the field and you don't need to insert date yourself


Re: Minor MySQL question. - _rAped - 01.01.2011

Nvm got it now.