Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-01-2005, 05:37 PM SQL Search Problem
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
Hi,

Would anyone know how to code a query to search a date field for certain things. For example, if I had a date in a date field with the format MM/DD/YYYY how would I search the database and only retrieve the data for just the month or a particular day. I would even like to search for dates within a month like from 01/01/2001 to 01/07/2001.

I can code the information to go into the database but I'm unsure how to code this type of query


Thanks in advance...........
merlin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-01-2005, 08:25 PM
Phaedrus's Avatar
Ultra Talker

Posts: 271
Location: CA
Trades: 0
I don't know how to do it with a DATE field, but with a DATETIME field you can query it like this:
Code:
SELECT field FROM table WHERE datetime_field >= ADDDATE(NOW(),INTERVAL -24 HOUR)
I like DATETIME fields because you might as well know the exact time, right? More data is better than less. And it lets you select records based on a time range, like the example above. You can change -24 HOUR to any number of hours or use DAY, MINUTE etc.

Edit: Also, MySQL stores the time in UTC time, so the time may not be the same as where you are. A little PHP can take care of that though, and make it display your local time.
__________________

Please login or register to view this content. Registration is FREE

Last edited by Phaedrus; 04-01-2005 at 08:27 PM..
Phaedrus is offline
Reply With Quote
View Public Profile
 
Old 04-06-2005, 11:17 AM query
Average Talker

Posts: 29
Trades: 0
Quote:
Originally Posted by merlin
Hi,

Would anyone know how to code a query to search a date field for certain things. For example, if I had a date in a date field with the format MM/DD/YYYY how would I search the database and only retrieve the data for just the month or a particular day. I would even like to search for dates within a month like from 01/01/2001 to 01/07/2001.

I can code the information to go into the database but I'm unsure how to code this type of query


Thanks in advance...........
you can write following statment to retreive result

select * from tablename where between date1 and date2
use between keyword to range your date.

mail me if you dont solve this query
chetanrakesh@yahoo.com
chetanrakesh is offline
Reply With Quote
View Public Profile Visit chetanrakesh's homepage!
 
Reply     « Reply to SQL Search Problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19875 seconds with 12 queries