niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » MySQL
How to query on part of a date column?
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
Author Message
Barry Newton
*nix forums beginner


Joined: 20 Jul 2006
Posts: 1

PostPosted: Thu Jul 20, 2006 5:02 pm    Post subject: How to query on part of a date column? Reply with quote

I've got a table of people who registered for a convention. Each person
has a registration date, kept in a standard date field. How do I select
for people who registered in a particular month or year? The obvious tests
like:

Select * from Capclave2005reg
Where Year('Date Paid') = 2004;

return no rows. I can extract any piece of that date I want in a SELECT,
but can't seem to use it in a WHERE clause at all. There has to be
something really obvious that I'm missing?


Barry Newton



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org
Back to top
Dan Buettner
*nix forums Guru Wannabe


Joined: 13 Oct 2005
Posts: 119

PostPosted: Thu Jul 20, 2006 5:31 pm    Post subject: Re: How to query on part of a date column? Reply with quote

Barry, I think you've got too many quotes in your SQL - the db is
trying to find the year from the string 'date paid'. You want to use
it as a column name, so drop the quotes:

Select * from Capclave2005reg
Where Year(Date Paid) = 2004;

If you've really got a space in your column name, try enclosing it in
backticks instead of quotes - ` instead of ', as in

Select * from Capclave2005reg
Where Year(`Date Paid`) = 2004;

Regards,
Dan

On 7/20/06, Barry Newton <bnewton@ashcomp.com> wrote:
Quote:
I've got a table of people who registered for a convention. Each person
has a registration date, kept in a standard date field. How do I select
for people who registered in a particular month or year? The obvious tests
like:

Select * from Capclave2005reg
Where Year('Date Paid') = 2004;

return no rows. I can extract any piece of that date I want in a SELECT,
but can't seem to use it in a WHERE clause at all. There has to be
something really obvious that I'm missing?


Barry Newton



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=drbuettner@gmail.com



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org
Back to top
mos
*nix forums Guru Wannabe


Joined: 21 Feb 2005
Posts: 103

PostPosted: Thu Jul 20, 2006 7:44 pm    Post subject: Re: How to query on part of a date column? Reply with quote

At 12:02 PM 7/20/2006, you wrote:
Quote:
I've got a table of people who registered for a convention. Each person
has a registration date, kept in a standard date field. How do I select
for people who registered in a particular month or year? The obvious
tests like:

Select * from Capclave2005reg
Where Year('Date Paid') = 2004;

return no rows. I can extract any piece of that date I want in a SELECT,
but can't seem to use it in a WHERE clause at all. There has to be
something really obvious that I'm missing?


Barry Newton

Barry,
I strongly recommend getting rid of the spaces in your
column/table names and replace them with an underscore character "_". You
are only creating problems for yourself if you leave the blanks in the names.

Mike

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org
Back to top
Martin Jespersen
*nix forums beginner


Joined: 20 Jun 2006
Posts: 18

PostPosted: Thu Jul 20, 2006 11:20 pm    Post subject: Re: How to query on part of a date column? Reply with quote

As long as backticks are used around fieldnames, spaces and/or reserved
words are fine, tho it does tend to create more work for the user ;)

mos wrote:
Quote:
At 12:02 PM 7/20/2006, you wrote:
I've got a table of people who registered for a convention. Each
person has a registration date, kept in a standard date field. How do
I select for people who registered in a particular month or year? The
obvious tests like:

Select * from Capclave2005reg
Where Year('Date Paid') = 2004;

return no rows. I can extract any piece of that date I want in a
SELECT, but can't seem to use it in a WHERE clause at all. There has
to be something really obvious that I'm missing?


Barry Newton

Barry,
I strongly recommend getting rid of the spaces in your
column/table names and replace them with an underscore character "_".
You are only creating problems for yourself if you leave the blanks in
the names.

Mike


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org
Back to top
mos
*nix forums Guru Wannabe


Joined: 21 Feb 2005
Posts: 103

PostPosted: Fri Jul 21, 2006 1:50 am    Post subject: Re: How to query on part of a date column? Reply with quote

At 06:20 PM 7/20/2006, Martin Jespersen wrote:
Quote:
As long as backticks are used around fieldnames, spaces and/or reserved
words are fine, tho it does tend to create more work for the user Wink

Correct. But how many people want to create more work for themselves? A
show of hands please!<bg>

Mike


Quote:
mos wrote:
At 12:02 PM 7/20/2006, you wrote:
I've got a table of people who registered for a convention. Each person
has a registration date, kept in a standard date field. How do I select
for people who registered in a particular month or year? The obvious
tests like:

Select * from Capclave2005reg
Where Year('Date Paid') = 2004;

return no rows. I can extract any piece of that date I want in a
SELECT, but can't seem to use it in a WHERE clause at all. There has to
be something really obvious that I'm missing?


Barry Newton
Barry,
I strongly recommend getting rid of the spaces in your
column/table names and replace them with an underscore character "_".
You are only creating problems for yourself if you leave the blanks in
the names.
Mike

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
The time now is Mon Dec 01, 2008 9:10 pm | All times are GMT
navigation Forum index » Databases » MySQL
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Very slow query Michael Sutter MySQL 0 Fri Jul 21, 2006 1:10 pm
No new posts Problem with Date::Manip Ted Byers Perl 1 Fri Jul 21, 2006 4:23 am
No new posts Last login date Evan Ehrenhalt Server 1 Thu Jul 20, 2006 10:07 pm
No new posts Column info without executing query Dan Strömberg PostgreSQL 10 Thu Jul 20, 2006 6:21 pm
No new posts recursive query Jürg Schaufelberger Server 1 Thu Jul 20, 2006 6:06 pm

Remortgages | Consumer information | Loans | Loans | Consumer information
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.5569s ][ Queries: 16 (0.4560s) ][ GZIP on - Debug on ]