select between date and time mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
junjustkim
Forum Commoner
Posts: 44
Joined: Thu May 22, 2008 8:48 pm

select between date and time mysql

Post by junjustkim »

hi to all

I have field date and time respectively. I want to select date between (date1 and time1 > 17) and (date2 < 17)

I tried in two ways but it doesn't work, please see code below.

any suggestions would greatly appreciated

tnx

tirso

Code: Select all

 
SELECT * from purchases_suppliers WHERE (date_invoice >= '2009/02/25' and time_invoice > 17) AND (date_invoice <= '2009/02/27' AND time_invoice < 17)

Code: Select all

SELECT * from purchases_suppliers WHERE date_invoice between ('2009/02/25' ANd time_invoice > 17) AND ('2009/02/27' AND time_invoice < 17 )
Dinosoles
Forum Newbie
Posts: 8
Joined: Fri Feb 20, 2009 1:07 am

Re: select between date and time mysql

Post by Dinosoles »

Hi,

It does depend on the type of fields, if the date_invoice was stored as datetime then this would workfine...

Code: Select all

SELECT * from purchases_suppliers WHERE date_invoice BETWEEN '2009/02/25 17:00:00' AND '2009/02/27 16:59:59'
If not then try the MySql DATE_FORMAT function.

Hope this helps.
Post Reply