用于选择两个日期之间的日期的SQL查询

时间:2022-09-09 14:16:42

I am trying to get date between two dates but i could not sort it out . Is it due my wrong date format or it is something other thing i am missing???

我想在两个日期之间得到日期,但我无法解决它。它是由于我错误的日期格式或它是我缺少的其他东西???

       SELECT * FROM (`employee`) WHERE `date` BETWEEN 2013-06-03 AND 2013-06-05

3 个解决方案

#1


0  

I have never used between statements before,

我以前从未使用过之间的陈述,

I think it should be;

我认为应该是;

SELECT * FROM (`employee`) WHERE `date` BETWEEN "2013-06-03" AND "2013-06-05"

with quotes, just a typo...

有报价,只是一个错字......

I personnally prefer;

我个人更喜欢;

SELECT * FROM employee WHERE Date >= '03/06/2013' AND Date <= '05/06/2013'";

#2


0  

I'll think comparing the unix timestamp of date should work for you:

我认为比较日期的unix时间戳应该适合你:

SELECT * FROM emloyee WHERE 
     UNIX_TIMESTAMP( date ) >= UNIX_TIMESTAMP('2013-06-03') 
 AND UNIX_TIMESTAMP( date ) <= UNIX_TIMESTAMP('2013-06-05') 

ref: MYSQL UNIX_TIMESTAMP()

ref:MYSQL UNIX_TIMESTAMP()

#3


0  

Try this

SELECT * FROM (`employee`) WHERE `date` BETWEEN STR_TO_DATE('2013-06-03','%Y-%m-%d') AND STR_TO_DATE('2013-06-05','%Y-%m-%d');

#1


0  

I have never used between statements before,

我以前从未使用过之间的陈述,

I think it should be;

我认为应该是;

SELECT * FROM (`employee`) WHERE `date` BETWEEN "2013-06-03" AND "2013-06-05"

with quotes, just a typo...

有报价,只是一个错字......

I personnally prefer;

我个人更喜欢;

SELECT * FROM employee WHERE Date >= '03/06/2013' AND Date <= '05/06/2013'";

#2


0  

I'll think comparing the unix timestamp of date should work for you:

我认为比较日期的unix时间戳应该适合你:

SELECT * FROM emloyee WHERE 
     UNIX_TIMESTAMP( date ) >= UNIX_TIMESTAMP('2013-06-03') 
 AND UNIX_TIMESTAMP( date ) <= UNIX_TIMESTAMP('2013-06-05') 

ref: MYSQL UNIX_TIMESTAMP()

ref:MYSQL UNIX_TIMESTAMP()

#3


0  

Try this

SELECT * FROM (`employee`) WHERE `date` BETWEEN STR_TO_DATE('2013-06-03','%Y-%m-%d') AND STR_TO_DATE('2013-06-05','%Y-%m-%d');