Archives by date

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Archives by date

Post 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.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

<, >, <=, >=

Code: Select all

SELECT something FROM table WHERE date < $date ORDER BY id";
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Check out MySQL's date and time functions:
http://www.mysql.com/doc/en/Date_and_ti ... tions.html

Mac
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

ok, that good.

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

Thanks.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Thanks.

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