timestamp mysql
#1

My question is the following

If I have a timestamp field in mysql and the date is saved in this way:

Код:
eg
'2016-09-15 08:36:21'
year-month-day hour:minute:second
How I can select the registers that for example are inactive for 1 year, or 1 month but just only mysql code?

I think that to do is comparing Unix time but I'm not quite clear how do it without use pawn code.
Reply
#2

PHP код:
new date[11], time[11], yearmonthdayhourminutesecond;
sscanf("2016-09-15 08:36:21""s[11]s[11]"datetime);
sscanf(date"p<->ddd"yearmonthday);
sscanf(time"p<:>ddd"hourminutesecond); 
Now you have everything you need to compare
Reply
#3

Quote:
Originally Posted by Shinja
Посмотреть сообщение
PHP код:
new date[11], time[11], yearmonthdayhourminutesecond;
sscanf("2016-09-15 08:36:21""s[11]s[11]",datetime);
sscanf(date"p<->ddd"yearmonthday);
sscanf(time"p<:>ddd"hourminutesecond); 
I know do that, I wanted to know if it could be done only with MySQL code.

Something like:

'where date < olddate'

?

It is to select many registers at once.
Reply
#4

Then you need to save each info in a column

Код:
Year     Month      Day
2016     09         15
Reply
#5

really?
Reply
#6

An example of selecting all the players (their name only) that are inactive for 1 or more years:
pawn Код:
SELECT name FROM players WHERE TIMESTAMPDIFF(YEAR, last_login, NOW()) >= 1;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)