Unixtime SQL help!!!!

Unixtime SQL help!!!!

am 23.11.2005 01:15:49 von lane.dj

I'am having a problem with an SQL statement...


MySql Database Table structure for phpnews_news is
id int unsigned auto_increment primary key,
posterid int,
postername char(40),
time int,
etc ......


The Time column is populated using a php time() function.


How do I use the TIME column to give me only the last 7 days worth of
data. Not sure how to manipulate unixtime formats... any help would be
appreciated..


SELECT * FROM PHPNEWS_NEWS where time between
DATE_SUB(CURDATE(),INTERVAL 30 DAY) and curdate()


Any help would be appreciated...


Dan

Re: Unixtime SQL help!!!!

am 23.11.2005 07:41:43 von Shion

lane.dj@gmail.com wrote:
> I'am having a problem with an SQL statement...
>
> The Time column is populated using a php time() function.
>
> How do I use the TIME column to give me only the last 7 days worth of
> data. Not sure how to manipulate unixtime formats... any help would be
> appreciated..

A week is 604800 seconds, so you need to get the current time and then reduce
that with 604800 seconds or you can use the mktime to create a the time for
midnight of today, so that you can get all of entries a week ago.

mktime(0,0,0,date('n'),date('j'))



//Aho