Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

querying on timestamp field for certain month or day
Welcome, Guest. Please login or register.
December 04, 2008, 12:17:14 AM
11306 Posts in 1249 Topics by 499 Members
Latest Member: haulaslemycle
Experts Round Table Network  |  Databases  |  MySQL  |  querying on timestamp field for certain month or day « previous next »
Pages: [1]
Author Topic: querying on timestamp field for certain month or day  (Read 381 times)
klitscher

Offline Offline

Posts: 24


« on: October 18, 2006, 08:31:53 PM »

I'm writing some software in php to organize news and events for a school committee and want to start an archive function.  The News and events have a timestamp that marks when the event takes place or when the news was posted.  If I want to return all of the events that happened in september of 2006, how would I construct a sql query on the timestamp field to select those events?  I've tried googling and looking at the dev.mysql.com but just don't know where to start.  Thanks,
Ken
Logged
rdivilbiss
Governing Council Member
*
Offline Offline

Posts: 414



WWW
« Reply #1 on: October 18, 2006, 08:44:58 PM »

You didn't say what database or how the timestampt wass generated, but assuming MySQL using NOW to create the timestamp, then:

SELECT *
FROM `yourTable`
WHERE month( timeStampField ) = '9'
AND year( timeStampField ) = '2006'

should do the trick.
Logged

Rod
klitscher

Offline Offline

Posts: 24


« Reply #2 on: October 18, 2006, 08:57:42 PM »

Sorry...thought the database was obvious, as it's in the MySQL forum...and the timestamps are either done using NOW() or inserted using the mysql datetime format.  I'll give it a try...thanks!

Ken
Logged
klitscher

Offline Offline

Posts: 24


« Reply #3 on: October 18, 2006, 09:31:14 PM »

worked like a charm...thanks so much
Logged
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #4 on: October 18, 2006, 11:33:32 PM »

too bad I was asleep ;-)

select * from yourtable where datetimestamp like '2006-09%' order by datetimestamp DESC LIMIT xxx;

may be faster
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
Pages: [1]
« previous next »
    Jump to: