corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » MYSQL help


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author MYSQL help
Rab
Member

Registered: 10th Jun 07
Location: Alloa, Scotland Drives: Subaru Hawkeye STi
User status: Offline
2nd May 08 at 13:42   View User's Profile U2U Member Reply With Quote

Doing a project at uni, and I am trying to query the table for sales made within a certain time.

I have been using this:

code:
SELECT `transaction_number` , `user_id` , `item_number` , `date_of_trans` , `total_cost`
FROM `cstransactions`
WHERE `date_of_trans` between `2008-04-01` and `2008-05-30`


And I get this error:

MySQL said: Documentation
#1054 - Unknown column '2008-04-01' in 'where clause'

The table has these values:

date_of_trans
2008-05-01
2008-04-03
2008-05-02

I'm not any good at MYSQL, just a beginner, but I can't see where its going tits up

Any ideas? Cheers!

[EDIT] Just managed to sort of fix it, I just removed the ` from around the data. Im guessing when you use ` it looks to it as if it was a table. But there is still a slight problem - it displays no data, but there is actually data in there. The field data type is DATE btw. Does it mess up when using between dates? Been doing other betweens fine.


[Edited on 02-05-2008 by RabR89]
ed
Member

Registered: 10th Sep 03
User status: Offline
2nd May 08 at 14:05   View User's Profile U2U Member Reply With Quote

I'm pretty sure that you can't use a BETWEEN statement in the way you want using the date formatted in that way....

What you want to do is to set the date_of_trans to a date in the MySQL database. Then when you put the dates into the database you need to have them formatted as a UNIX timestamp.
Rab
Member

Registered: 10th Jun 07
Location: Alloa, Scotland Drives: Subaru Hawkeye STi
User status: Offline
2nd May 08 at 14:28   View User's Profile U2U Member Reply With Quote

Okay, tried what you suggested, but when I set it to the UNIX_TIMESTAMP the dates are set to 0000-00-00. Then when I change them to what I need, and click save, when I Browse the table again, they seem to go back to 0000-00-00.
James
Member

Registered: 1st Jun 02
Location: Surrey
User status: Offline
2nd May 08 at 14:33   View User's Profile U2U Member Reply With Quote

Or you can cast the string as a date in the query....
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
2nd May 08 at 15:05   View Garage View User's Profile U2U Member Reply With Quote

SELECT *
FROM cstransactions
WHERE date_of_trans BETWEEN CAST('2008-04-01' AS DATE) AND CAST('2008-05-30' AS DATE)

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Linking .jsp pages to a MySQL database chris_lee100 Geek Day 7 1383
1st Feb 04 at 14:23
by Ian
 
forum hacking - SQL's Drew Geek Day 15 1698
9th Sep 04 at 23:50
by Ian
 
Server Help Jodi_the_g Geek Day 7 1435
19th Jan 06 at 15:18
by Jodi_the_g
 
My SQL-Nearly there! Tom J Geek Day 31 3140
25th Dec 06 at 23:32
by Ian
 

Corsa Sport » Message Board » Off Day » Geek Day » MYSQL help 29 database queries in 0.0116911 seconds