我正在使用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 - 通过忽略日期中的时间部分来显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22373465/