LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-19-2006, 08:16 AM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
selecting information by date in mysql


hello all,

i want to be able to select all the information that is in on of my tables that is over six months old in mysql, how can i do this?

the table has a date column with the date that it was created called createdOn. cheers trscookie
 
Old 07-19-2006, 08:52 AM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
I believe you can simply use the where clause of a select statement like this:
Code:
select * from table where createdOn >= start and createdOn < end
where table is the name of the table, and start and end are the date ranges of the selection in the form "YYYYMMDD" e.g. "20060719".
 
Old 07-20-2006, 09:28 PM   #3
smallville
Member
 
Registered: Dec 2005
Posts: 44

Rep: Reputation: 15
use interval

select * from tablename where datecol <= curdate() - interval 6 month
 
Old 07-20-2006, 09:53 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
smallville is correct.

But I think on older versions of mysql, you might have to use syntax like:
Quote:
DATE_SUB(NOW(), INTERVAL 1 MONTH);
 
Old 07-21-2006, 05:07 AM   #5
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about getting the date/time information from a file shazam75 Linux - General 1 10-31-2004 07:54 AM
show date in mysql bentman78 Linux - Software 0 05-17-2004 11:44 AM
MySQL date format mnauta Linux - General 2 05-13-2004 06:20 PM
editing mysql information Nay Linux - Newbie 2 11-10-2003 03:44 AM
Changing date format in MySQL table vous Linux - Software 8 09-03-2003 06:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration