简体   繁体   English

如何在MySQL中的特定日期之间获取值

[英]How to get the values between particular date in mysql

I want to get the values between particular date and time. 我想获取特定日期和时间之间的值。 But each values - time, hour and minutes are there in separate fields. 但是每个值-时间,小时和分钟都在单独的字段中。

Following is the table format i have, 以下是我的表格格式,

Date        Hour    Min     values

1/1/2011    10      30      Test1
2/1/2011    8       10      Test2
3/1/2011    15      40      Test3
5/1/2011    11      10      Test5
10/1/2011   3       04      Test6
12/1/2011   5       00      Test6

Now i want to get the "values" between '3/1/2011 12.00' and '10/1/2011 11.10' using MYSQL SELECT query. 现在,我想使用MYSQL SELECT查询获取“ 2011年3月1日12.00”和“ 2011年10月1日10”之间的“值”。 If anyone knows pls help me 如果有人知道请帮助我

You can do like this: 您可以这样:

SELECT id, CONCAT(dateval,' ',hourval,':',minval,':00') as t 
 FROM ForgeRock 
 WHERE CAST(CONCAT(dateval,' ',hourval,':',minval,':00') as DATETIME) 
  between CAST('2006-01-21 17:10:00' as DATETIME) AND 
   CAST('2006-01-25 22:10:00' as DATETIME) 

Because of concate() we need to use CAST to convert them as datetime. 由于concate(),我们需要使用CAST将其转换为日期时间。 SQL fiddle for it: http://sqlfiddle.com/#!9/4a072/12 SQL提琴为此: http ://sqlfiddle.com/#!9/ 4a072/12

Updating @Suresh answer, as the default date format is 'Ym-d'. 更新@Suresh答案,因为默认date格式为'Ym-d'。

SELECT values
FROM table_name
WHERE `Date` between '2011-01-03' and '2011-10-01' 

We can also use alternate of Between.. 我们也可以使用之间的替代。

SELECT *
FROM table
WHERE Date >= '2011-01-03' and Date < '2011-10-01'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM