SSRS: Useful Date & Time Functions

Share this blog:
  •  
  •  
  •  
  •  
  •  

CDate
Convert to Date.
=CDate(Fields!BirthDate.Value)

DateAdd
Returns a Date value containing a date and time value to which a specified time interval has been added.
=DateAdd(“d”,3,Fields!BirthDate.Value)
=DateAdd(DateInterval.Day,3,Fields!BirthDate.Value)

DateDiff
Returns a Long value specifying the number of time intervals between two Date values.
=DateDiff(“yyyy”,Fields!BirthDate.Value,”1/1/2007″)
=DateDiff(DateInterval.Year,Fields!BirthDate.Value,”1/1/2007″)

DatePart
Returns an Integer value containing the specified component of a given Date value.
=DatePart(“q”,Fields!BirthDate.Value,0,0)
=DatePart(DateInterval.Quarter,Fields!BirthDate.Value,FirstDayOfWeek.System,FirstWeekOfYear.System)

DateSerial
Returns a Date value representing a specified year, month, and day, with the time information set to midnight (00:00:00).
=DateSerial(DatePart(“yyyy”,Fields!BirthDate.Value)-10, DatePart(“m”,Fields!BirthDate.Value)+3, DatePart(“d”, Fields!BirthDate.Value)-1)
=DateSerial(DatePart(DateInterval.Year, Fields!BirthDate.Value)-10, DatePart(“m”,Fields!BirthDate.Value)+3,DatePart(“d”,Fields!BirthDate.Value)-1)
=DateSerial(2007,10,24)

DateString
Returns or sets a String value representing the current date according to your system.
=DateString()
=DatePart(“m”,DateString())
DateValue
Returns a Date value containing the date information represented by a string, with the time information set to midnight (00:00:00).
=DateValue(“January 15, 2007”)
Day
Returns an Integer value from 1 through 31 representing the day of the month.
=Day(Fields!BirthDate.Value)

FormatDateTime
Returns a string expression representing a date/time value.
=FormatDateTime(Fields!BirthDate.Value, DateFormat.ShortDate)

Hour
Returns an Integer value from 0 through 23 representing the hour of the day.
=Hour(Fields!BirthDate.Value)

Minute
Returns an Integer value from 0 through 59 representing the minute of the hour.
=Minute(Fields!BirthDate.Value)

Month
Returns an Integer value from 1 through 12 representing the month of the year.
=Month(Fields!BirthDate.Value)

MonthName
Returns a String value containing the name of the specified month.
=MonthName(10,True)
=MonthName(Month(Fields!BirthDate.Value),False)
=”The month of your birthday is ” & MonthName(Month(Fields!BirthDate.Value))

Now
Returns a Date value containing the current date and time according to your system.
=Now()
=”This time tomorrow is ” & DateAdd(“d”,1,Now())
=”This time tomorrow is ” & DateAdd(DateInterval.Day,1,Now())

Second
Returns an Integer value from 0 through 59 representing the second of the minute.
=Second(Fields!BirthDate.Value)

TimeOfDay
Returns or sets a Date value containing the current time of day according to your system.
=TimeOfDay()
=”Time of the day is ” & TimeOfDay()

Timer
Returns a Double value representing the number of seconds elapsed since midnight.
=Timer()
=”Number of seconds since midnight ” & Timer()

TimeSerial
Returns a Date value representing a specified hour, minute, and second, with the date information set relative to January 1 of the year 1.
=TimeSerial(DatePart(“h”,Fields!BirthDate.Value), DatePart(“n”,Fields!BirthDate.Value),DatePart(“s”,Fields!BirthDate.Value))
=TimeSerial(DatePart(DateInterval.Hour,Fields!BirthDate.Value), DatePart(DateInterval.Minute,Fields!BirthDate.Value), DatePart(DateInterval.Second,Fields!BirthDate.Value))
=TimeSerial(23,49,52)

TimeString
Returns or sets a String value representing the current time of day according to your system.
=TimeString()

TimeValue
Returns a Date value containing the time information represented by a string, with the date information set to January 1 of the year 1.
=TimeValue(“16:20:17”)
=TimeValue(Fields!BirthDate.Value)

Today
Returns or sets a Date value containing the current date according to your system.
=Today()
=”Tomorrow is ” & DateAdd(“d”,1,Today())
=”Tomorrow is ” & DateAdd(DateInterval.Day,1,Today())

Weekday
Returns an Integer value containing a number representing the day of the week.
=Weekday(Fields!BirthDate.Value,0)
=Weekday(Fields!BirthDate.Value,FirstDayOfWeek.System)

WeekDayName
Returns a String value containing the name of the specified weekday.
=WeekdayName(2,True,0)
=WeekDayName(DatePart(“w”,Fields!BirthDate.Value),True,0)
=WeekDayName(DatePart(DateInterval.Weekday,Fields!BirthDate.Value),True,FirstDayOfWeek.System)

Year
Returns an Integer value from 1 through 9999 representing the year.
=Year(Fields!BirthDate.Value)

Leave a Reply

Your email address will not be published. Required fields are marked *

18 − 14 =