SSRS How to define parameters as 7 days ago plus 1 hour

吃可爱长大的小学妹 提交于 2019-12-11 09:27:47

问题


I have a report made using SSRS and SQL Server and I have set a StartDate and EndDate parameters for the report.

I have set the default value for StartDate as =DateAdd("D", -7, Today()) I have set the default value for EndDate as =DateAdd("H", 1, Today())

How can I add 1 hour to the StartDate Parameter?

I've tried

=DateAdd("H", 1, (DateAdd("D", -7, Today())))

Would that work? I'm currently testing it but the report usually takes 6 hours to run.


回答1:


Do the date math in hours instead of days.

=DateAdd("H", -169, Today())



回答2:


Would that work? You can always try that in SQL Server. The answer is yes :o)

Although, you should use the NOW() function instead of the TODAY() function (see the Update below).

SQL Server:

SELECT DATEADD(HH, 1, DATEADD(DD, -7, GETDATE()))

SSRS/VS:

DateAdd(DateInterval.Hour, -167, Now())

Update: To Larnu's point, Today() will default as a date format of MM/DD/YYYY. If you only subtract 167 hours from Today, then the field will show in date time, but the result will be incorrect as it will show 1:00 AM for the time. So use the NOW() function, instead of TODAY(). The result will be 167 hours from the current time and will be in the format of MM/DD/YYYY HH:MM:SS.

Also, you can make the change in the parameter field and click on the Preview in VS to see these changes. You would not need to run the report to see this change. That, or I do not understand what you are trying to accomplish.



来源:https://stackoverflow.com/questions/49680577/ssrs-how-to-define-parameters-as-7-days-ago-plus-1-hour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!