Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
852 views
in Technique[技术] by (71.8m points)

how to get date between two dates in mysql?

In MySql database have AM_TIMETABLE table in that

UserId        DateTime
 101        2012-08-08 04:00:00 
 102        2012-08-15 10:00:00
 103        2012-08-18 09:00:00
 104        2012-08-24 05:00:00

My Question is, i'm passing start-date and end-date then i'll get DateTime column date for ex:

select * from AM_TIMETABLE where DateTime<='2012-08-08 00:00:00' and DateTime>='2012-08-20 00:00:00'

then i will get 101,102,103 UserId's value. but i'm getting error please help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

BETWEEN is much better for this. and you must also escape DateTime since it is a reserve word.

SELECT * 
FROM   AM_TIMETABLE 
WHERE  `DateTime` BETWEEN '2012-08-08 00:00:00' AND '2012-08-20 00:00:00'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...