Minor MySQL question.
#1

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

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

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

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

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

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();
Reply
#7

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

if(gettime() > mysql_fetch_int()) => expired
Reply
#8

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

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

Nvm got it now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)