RDLC报表格式化format表达式

本文探讨了RDLC报表中日期格式化的局限性及解决方案,对比了FormatDateTime函数与Format函数的使用,展示了如何利用Format函数实现更灵活的日期格式定制。

刚开始接触RDLC报表,觉得RDLC报表提供的格式化工具太少,不像Crystal Report一样那么多的API支持,用起来多少的灵活啊。

由于RDLC报表中有相关的日期格式字段,因此自然而然的就需要对日期字段进行格式化了,搜索了一些文章都是在介绍

FormatDateTime函数,其实用起来就发现FormatDateTime不是我要的料,这此先看看FormatDateTime的声明吧:

 

Function FormatDateTime(
   ByVal Expression As DateTime,
   Optional ByVal NamedFormat As DateFormat = DateFormat.GeneralDate
As String
DateFormat是一个枚举,其值很少不太适合中国人制作报表的习惯,

NamedFormat 参数具有下列设置:

常量说明
DateFormat.GeneralDate显示日期和/或时间。如果有日期部分,则用短日期格式显示。如果有时间部分,则用长时间格式显示。如果二者都有,则两部分都显示。
DateFormat.LongDate使用计算机的区域设置中指定的长日期格式来显示日期。
DateFormat.ShortDate使用计算机的区域设置中指定的短日期格式来显示日期。
DateFormat.LongTime使用计算机区域设置中指定的时间格式来显示时间。
DateFormat.ShortTime使用 24 小时格式 (hh:mm) 显示时间。

 

FormatDateTime(Fields!PlanStartDate.Value,DateFormat.ShortDate)

 

Command Result
FormatDateTime(Parameters!Date.Value,1) Tuesday, April 10, 2007
FormatDateTime(Parameters!Date.Value,2) 4/10/2007
FormatDateTime(Parameters!Date.Value,3) 12:00:00 AM
FormatDateTime(Parameters!Date.Value,4) 00:00


 
如果我想通过FormatDateTime将日期格式显示成“2012年4月”,那就很难了。

 

 

 解决方法

The Format command and specify the exact format you require.

好Format函数现已隆重出场了,因此他确实可以解决我的问题,而且使用习惯与DateTime.ToString()类似,非常简单:

Command Result
Format(Parameters!Date.Value,"dd-MM-yyyy") 10-04-2007
Format(Parameters!Date.Value,"dd/MM/yyyy") 10/04/2007
Format(Parameters!Date.Value,"MMM-dd-yyyy") Apr-10-2007
Format(Parameters!Date.Value,"MMM-dd-yy") Apr-10-07

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值