SQLTeam.com | Weblogs | Forums

Display current run time -12 hours in report header


#1

am trying to display the report time frame in the header of the report.
I have a report that retrieves date from current date - 12 hours. I tried below and I get yesterday.
=DATEADD("h", -12,(today))
if I run the report at 7:00 am I would like the start date to show
mm/dd/yyyy 7:00 pm and the end date to show mm/dd/yyyy 7:00 am.

I have no problem for my monthly reports

First day of last month:
=dateadd("m",-1,dateserial(year(Today),month(Today),1))

[left][/left]

can someone please help???


#2

I don't know much about SSRS/reporting but isn't "TODAY" a date with no time? Isn't there something like "NOW" that does have both a date and a time associated with it?


#3

@JeffModen is right, you should use NOW() if you want to get date and time. Then use DATEADD function and FORMAT function to do what you need. For example:

=Format(DateAdd("h",-12,Now()),"MM/dd/yyyy hh:00 tt")
& " to "
& Format(Now(),"MM/dd/yyyy hh:00 tt")

You can format it to your liking using the standard format strings from here or, if that does not meet your requirements, using the custom format strings on this page.


#4

thank you very much, just what I was looking for.