Easy Question

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
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Easy Question

Post by AliasBDI »

I am creating a SQL database for holding articles online. I will have the articles queried according to the 'date_created'. In the database, 'date_created' is a TimeStamp field. Is it possible for PHP to query that field and determine the year, month, and day of each record in order to give queried results.

Basically, in user terms... A user will go to the ARCHIVE section and click on 2002. It will show the 12 months as links. Then the user will click on FEBRUARY and the next page will list all 2002 February articles (according to the query of 'date_created'

I guess another way of doing this is seperating the YEAR, MONTH, DAY into seperate fields - but that is definitely a long way. Any ideas?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]mktime[/php_man]() & [php_man]strftime[/php_man]() :: check if the date_created values are BETWEEN (hint) December 31, 2001 23:59:59 and January 1, 2003 00:00:00
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

There are also some MySQL functions you maybe interested in:

MONTH(date)
Returns the month for date, in the range 1 to 12.

YEAR(date)
Returns the year for date, in the range 1000 to 9999.

13.5 Date and Time Functions
Post Reply