Experts Round Table Network
Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:
Password:
Remember me
Forgot your password?
Register
querying on timestamp field for certain month or day
Welcome,
Guest
. Please
login
or
register
.
December 04, 2008, 12:24:56 AM
11307
Posts in
1250
Topics by
500
Members
Latest Member:
jkkjkjjfhyaasass
Home
Help
Search
Login
Register
Experts Round Table Network
|
Databases
|
MySQL
|
querying on timestamp field for certain month or day
« previous
next »
Pages:
[
1
]
Print
Author
Topic: querying on timestamp field for certain month or day (Read 382 times)
klitscher
Offline
Posts: 24
querying on timestamp field for certain month or day
«
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
Posts: 414
Re: querying on timestamp field for certain month or day
«
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
Posts: 24
Re: querying on timestamp field for certain month or day
«
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
Posts: 24
Re: querying on timestamp field for certain month or day
«
Reply #3 on:
October 18, 2006, 09:31:14 PM »
worked like a charm...thanks so much
Logged
VGR
Mentor
Offline
Posts: 682
Re: querying on timestamp field for certain month or day
«
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
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
ERT 1.5
-----------------------------
=> Round Table Learning Center
=> Bug reports
-----------------------------
Legacy
-----------------------------
=> The next level
=> History of ERT
-----------------------------
Community Affairs
-----------------------------
=> Introductions
=> Ballot Box
===> Closed Polls
=> Soapbox
=> Propose and Consult
===> Propose and Consult...CLOSED
-----------------------------
Bits and Bytes
-----------------------------
=> Tips, Tricks, Snippets, Tidbits And General Pearls Of Wisdom
-----------------------------
Serverside Technology
-----------------------------
=> PHP
=> ASP
-----------------------------
Webservers
-----------------------------
=> Apache
=> IIS
-----------------------------
Databases
-----------------------------
=> MySQL
=> Access
=> MS SQL Server
-----------------------------
Clientside Technology
-----------------------------
=> HTML
=> CSS
=> Javascript
=> Flash
=> WAP/WML
-----------------------------
Web Technologies
-----------------------------
=> General Web Dev
=> Web Standards
=> XML
=> Online Marketing
-----------------------------
Graphics
-----------------------------
=> Graphics Design and Animation
-----------------------------
Programming
-----------------------------
=> .NET
=> JAVA
=> MS DOS Batch Scripting
=> Mathematics
=> C & C++
=> VB
=> Delphi
=> Algorithm design
-----------------------------
Operating Systems
-----------------------------
=> Windows (General)
=> NT Based (2K, 2K-03, NT, XP, Vista)
=> Open Source (All)
-----------------------------
Hardware
-----------------------------
=> Hardware General
=> Gamers Hardware (Advanced)
-----------------------------
Networking
-----------------------------
=> Home (small)
=> Office (large)
=> Internet
-----------------------------
Security
-----------------------------
=> General Security Issues
-----------------------------
Rants/Opinions/Proposals
-----------------------------
=> Site operation
Powered by SMF 1.1 RC2
|
SMF © 2001-2005, Lewis Media
Joomla Bridge by
JoomlaHacks.com