Page 1 of 1

Archives by date

Posted: Sun Oct 06, 2002 4:50 pm
by evilmonkey
Hello. I have a table in a MySQL database, and one of the fields in it is 'date'. I have a few questions.

1) In PHPmyADMIN, how do I set the default date to change everyday (If a user submits data in a form, I want that day's date to be automatically attached without any user input)

2) Say I want to dump everything older than 1 week into something called an archive. I write a script

Code: Select all

SELECT something FROM table WHERE date=? ORDER BY id";
What do I put in place of the question mark after 'date='?

Looking forward to a few answers :D

Thanks.

Posted: Mon Oct 07, 2002 1:38 am
by Takuma
<, >, <=, >=

Code: Select all

SELECT something FROM table WHERE date < $date ORDER BY id";

Posted: Mon Oct 07, 2002 1:55 am
by twigletmac
Check out MySQL's date and time functions:
http://www.mysql.com/doc/en/Date_and_ti ... tions.html

Mac

Posted: Mon Oct 07, 2002 12:06 pm
by evilmonkey
ok, that good.

Now how do I set the default date in PHPmy ADMIN to change every day?

Thanks.

Posted: Tue Oct 08, 2002 2:14 am
by twigletmac
AFAIK, you can't have PHPMyAdmin do this automatically but the CURDATE() function can be selected from the function dropdown list next to the fieldname when your are inserting a new record.

Mac

Posted: Tue Oct 08, 2002 12:44 pm
by evilmonkey
Thanks.

I also heard about the TIMESTAMP function. I'll see which one I use.