The SSRS TimeSerial function is a Date and Time function that constructs a time value from the specified hour, minute, and second information and sets the date value to January 1 of the year 1. The syntax of the TimeSerial function to build the required time from the hour, minute, and second is as shown below.
=TimeSerial(20, 45, 30)
To demonstrate the SSRS TimeSerial function, we use the Employee table below, which has 15 records. The image shows the records in the Table report.
SSRS TimeSerial function Example
For this, let me add a new column to the right side of the Hire Date column, and name it TimeSerial. Next, right-click the textbox under Now and choose the Expression. To understand the report, I suggest you refer to the articles on charts, tables, grouping, and format tables in SSRS.
It opens the following expression window to construct the date and time. We don’t have any dedicated columns with the hour, minute, and second information. First, the code below uses the DatePart function to get/extract the hour, minute, and second information from HireDate. To show the difference, we have added 8 hours and subtracted 10 minutes and 5 seconds from the Hire Date. Next, the SSRS TimeSerial function uses the extracted hour, minute, and second values to construct or build time information and set the date to 1/1/0001.
=TimeSerial(DatePart("h", Fields!HireDate.Value) + 8,
DatePart("n", Fields!HireDate.Value) - 10,
DatePart("s", Fields!HireDate.Value) - 5)
Similarly, let me add a new column. In this example, we use Hour, Minute, and Second functions to extract them from the Hire Date column. For more functions >> Click Here!
=TimeSerial(Hour(Fields!HireDate.Value) - 10,
Minute(Fields!HireDate.Value) + 15,
Second(Fields!HireDate.Value) - 30)
Please click the preview tab to see the report. As you can see, it sets the date to 01/01/0001 by default. If you want to show the time only, please click Text Box Properties -> Number. Next, change Category to Time and choose the type.