mysql - 通过忽略日期中的时间部分来显示数据

标签 mysql sql date plsql jasper-reports

我正在使用JasperReports/iReport来制作我的报告。我已经编写了一个查询,让客户端键入日期,但有 1 个问题,日期是与时间部分一起出现的。

如何忽略客户端输入数据的时间部分?

date                            rate
2/2/2014  12:56:21.0000 PM      ABC   
4/2/2014  12:56:21.0000 PM      EFG
5/2/2014  12:56:21.0000 PM      HIJ
...

I have assign from customer to design with the parameter of year,month, and day.In other words, when the customer key in the year,month,and day, the data will show this way:

2/2/2014  12:56:21.0000 PM      ABC

The query i have wrote is show below:

select date,rate 
  from mytable
 where rownum=1 
       and tran_dt<=(select date 
                       from mytable 
                      where year(date)=$P{year} 
                            and month(date)=$P{month} 
                            and day(date)=$P{day}
                     )
order by 
       date

我正在使用 pl/sql 查询...

最佳答案

SQL 服务器:

使用这个

 select convert(varchar(10), '2011-02-25 21:17:33.933', 120)

像这样

 Select DATE_FORMAT(date,'%y-%m-%d'),rate from mytable
where rownum=1 and tran_dt<=(select tran_dt from bi01_trandetail where
year(date)=$P{year} and month(tran_dt)=$P{month} and day(tran_dt)=$P{day})
order by date

MYSQL

使用

 DATE_FORMAT(date,'%y-%m-%d')


   Select DATE_FORMAT(date,'%y-%m-%d'),rate from mytable
   where rownum=1 and tran_dt<=(select tran_dt from bi01_trandetail where
   year(date)=$P{year} and month(tran_dt)=$P{month} and day(tran_dt)=$P{day})
   order by date

或者

SELECT DATE('2003-12-31 01:02:03');
'2003-12-31'



  Select date(date),rate from mytable
   where rownum=1 and tran_dt<=(select tran_dt from bi01_trandetail where
   year(date)=$P{year} and month(tran_dt)=$P{month} and day(tran_dt)=$P{day})
   order by date

您的新查询:

select date,rate 
  from mytable
 where rownum=1 
       and tran_dt<=(select DATE_FORMAT(date,'%y-%m-%d') 
                       from mytable 
                      where year(date)=$P{year} 
                            and month(date)=$P{month} 
                            and day(date)=$P{day}
                     )
order by 
       date

MYSQL DATE FUNCTION

关于mysql - 通过忽略日期中的时间部分来显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22373465/

相关文章:

java - 一个 sql 查询来检查唯一性

swift - 如何使用 DateToolsSwift 添加日期到日期?

c++ - 在 Visual Studio 中将字符串转换为日期对象

mysql - 在 mysql 中使用 SOME 查询没有给出预期结果。?

php - Laravel:如何查询多个间接相关的表?

mysql - SQL查询问题-当有最大数量时选择最短时间

mysql - 为什么 information_schema 和 Performance_schema 不是 utf8mb4 (我应该关心)?

sql - MYSQL 对同一类别进行多项选择?

R 中的 read.csv 阅读日期不同

Php mysqli_fetch_array 不起作用