PDA

View Full Version : Mysql question, selecting threads by date..


Jelmertjee
11-09-2007, 05:28 PM
I'm creating a sort of archive and need to select threads by their created date, so I'm trying to use dateline. I know you can use vbdate() to turn it into a normal, usable date but I don't think this is any use because I can only select the raw dateline from the database, right?

Of course it's possible to match the date after quering but then I would need to query way too many threads... Does anybody have a solution for this, so you can already select the right threads with a query? Or just an explanation of how the dateline is determined??

jamesmarch
11-09-2007, 05:57 PM
dateline is epoch time:
http://en.wikipedia.org/wiki/Unix_epoch

I think what you want to do is something like :

SELECT * from vb_thread where dateline <= UNIX_TIMESTAMP('2007-01-01 00:00:00');
This should select all threads created before 2007. UNIX_TIMESTAMP will convert a date to epoch time, which is the format dateline is in.

Also just for the sake of completeness, FROM_UNIXTIME(dateline) will go the other way.

SELECT dateline, FROM_UNIXTIME(dateline) from vb_thread;
will return dateline in epoch and normal yyyymmdd h:i:s format.

Jelmertjee
11-09-2007, 07:53 PM
Thanks a lot, I had already figured it out in the mean time in a slightly different way, using mktime() to convert a $month and $year variable into 2 timestamps and then selecting all the threads with a timestamp between those 2 values to select all the threads from one month. Again, thanks for your quick reply. :)

Paul M
11-09-2007, 11:37 PM
use vbmktime()