Reporting Services 从表达式中的 DateTime 中删除时间
我试图用明确的时间填充表达式(参数的默认值)。如何从“现在”功能中删除时间?
I'm trying to populate an expression (default value of a parameter) with an explicit time. How do I remove the time from the the "now" function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
像这样的事情:
其中“现在”可以替换为您尝试转换的日期/时间字段的名称。)
例如,
Something like this:
Where "Now" can be replaced by the name of the date/time field that you're trying to convert.)
For instance,
由于 SSRS 使用 VB,您可以执行以下操作:
如果您要使用:
Since SSRS utilizes VB, you can do the following:
If you were to use:
尽管您将日期格式硬编码为区域设置。
Although you are hardcoding the date formart to a locale.
如果您必须在报表标题上显示该字段,请尝试此...
右键单击文本框>属性>类别>日期>选择*格式(请注意,这将保留区域设置)。
由于这个问题已被查看多次,因此我将其发布...希望它有所帮助。
If you have to display the field on report header then try this...
RightClick on Textbox > Properties > Category > date > select *Format (Note this will maintain the regional settings).
Since this question has been viewed many times, I'm posting it... Hope it helps.
如果预期的数据格式是
MM-dd-yyyy
,则尝试以下,同样,您可以尝试这个,
< em>输出:
02-04-2016
注意:
Now()
将显示当前日期和时间戳今天( )
将仅向您显示日期,而不是时间部分。您还可以设置任何日期格式,而不是 >
MM-dd-yyyy
在我的示例中。If expected data format is
MM-dd-yyyy
then try below,Similarly you can try this one,
Output:
02-04-2016
Note:
Now()
will show you current date and time stampToday()
will show you Date only not time part.Also you can set any date format instead of
MM-dd-yyyy
in my example.如果您希望结果为
DateTime
数据类型,只需使用DateValue(Now)
即可。Just use
DateValue(Now)
if you want the result to be ofDateTime
data type.在任何文本框字段的格式属性中,您可以使用格式字符串:
例如 D/M/Y、D 等。
In the format property of any textbox field you can use format strings:
e.g. D/M/Y, D, etc.
可能对其他人有帮助的一件事是,您可以将:
=CDate(Now).ToString("dd/MM/yyyy")
放入 SSRS 的格式字符串属性中,可以通过右键单击柱子。这是最干净的方法。那么你的表达式就不会太大并且难以在视觉上“解析”:)One thing that might help others is that you can place:
=CDate(Now).ToString("dd/MM/yyyy")
in the Format String Property of SSRS which can be obtained by right clicking the column. That is the cleanest way to do it. Then your expression won't be too large and difficult to visually "parse" :)我来晚了,但我尝试了上面所有的解决方案!无法让它删除参数中的零并给我一个默认值(它忽略了格式或显示为空白)。我正在使用 SSRS 2005,因此正在努力解决其笨重/错误的问题。
我的解决方法是向我从中提取日期的数据库中的自定义 [DimDate] 表添加一列。我添加了一列,它是 [日期] 列所需格式的字符串表示形式。然后,我在 SSRS 中创建了 2 个新数据集,这些数据集引入了以下查询,以获取“收件人”和“收件人”的 2 个默认值。 “从”日期默认值 -
“从”
“到”
I'm coming late in the game but I tried all of the solutions above! couldn't get it to drop the zero's in the parameter and give me a default (it ignored the formatting or appeared blank). I was using SSRS 2005 so was struggling with its clunky / buggy issues.
My workaround was to add a column to the custom [DimDate] table in my database that I was pulling dates from. I added a column that was a string representation in the desired format of the [date] column. I then created 2 new Datasets in SSRS that pulled in the following queries for 2 defaults for my 'To' & 'From' date defaults -
'from'
'to'
我对日期/时间参数的解决方案:
技巧是按照停泊岛的建议转换回日期时间。
My solution for a Date/Time parameter:
The trick is to convert back to a DateTime as recommend Perhentian.
从此处<找到了解决方案/strong>
这获取前一天的最后一秒:
这将返回上周的最后一秒:
Found the solution from here
This gets the last second of the previous day:
This returns the last second of the previous week:
这应该在数据集中完成。您可以
在
SSRS
布局中执行此操作,只需执行以下操作=Fields!DateColumnName.Value
This should be done in the dataset. You could do this
In
SSRS
Layout, just do this=Fields!DateColumnName.Value
只需将一个字符串连接到值的末尾:
这应该可以工作!
Just concatenate a string to the end of the value:
and this should work!