Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: PS4DEV - maaliskuu 23, 2014, 05:42:41 IP

Otsikko: (MySql) Compare current date with post date
Kirjoitti: PS4DEV - maaliskuu 23, 2014, 05:42:41 IP
Hello,

I have some problems with comparing two timestamps in mysql.

I want so compare the current time with the timestamps of my posts, and take all the posts that have been created the last day (24 hours).

Here is what I tried so far:

WHERE  UNIX_TIMESTAMP(CURDATE()) - UNIX_TIMESTAMP(m.poster_time) <= 60*60*24

but I don“t get it working.

Can someone help, please ?

Otsikko: Re: (MySql) Compare current date with post date
Kirjoitti: vbgamer45 - maaliskuu 23, 2014, 05:55:30 IP
I would do something like
UNIX_TIMESTAMP(m.poster_time) >=  (UNIX_TIMESTAMP(CURDATE()) - 60*60*24)
Otsikko: Re: (MySql) Compare current date with post date
Kirjoitti: PS4DEV - maaliskuu 23, 2014, 06:12:21 IP
Thank you that helped.

I did myself another mistake,
you need to use NOW() and not CURDATE()

Here is the working code:
WHERE m.poster_time >=  (UNIX_TIMESTAMP(NOW()) - 60*60*24)