Home > SQL Server > SQL Reporting Services – Easy Date Function

SQL Reporting Services – Easy Date Function

Sometimes I use this simple but effective date function in my reports (NZ reports) by using the ‘Code’ functionality given by SQL Reporting Services.  Therefore I thought I would paste this on my site for quick reference. Feel free to use. 

Public Function FormatDate(ByVal d As Date)
 Return d.ToString("dd/MM/yyyy")
End Function

To find where to paste your code then simply goto ‘Report Properties’ from the Report Menu (in Report Designer) and select the ‘Code’ tab. Then paste your code inside the window made available and click OK.

Then to use in your reports, simply call it like the following …

=code.FormatDate(Fields!DATE.Value)

The function above also illustrates how you can write your own functions and call them within your report.

If you are ever wondering where your code will be stored then have a look inside your RDL (report exension .rdl) report file and search for the XML tags of <CODE></CODE>. You will notice it inside there.

Simple aye! Happy coding.

Yellow Duck Guy
Greg Olsen

Advertisements
Categories: SQL Server
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: