Reader Level:

Formatting Dates in Crystal Reports

By Mahesh Chand on Jun 14, 2007
Formatting a formula with a date value could be tricky in Crystal Reports. This article shows how to format date fields and date formulae in Crystal Reports.

If you have a DateTime field in Crystal Reports, you will see Date and Time tab option on the Format Editor when you right click on the field and select Format Field menu item. From the Date and Time tab, you may select the desired format and select OK.




Custom Date Format


If you do not see the desired format in the available list, you can also use the Customize button that launches Custom Style dialog.

The Custom Style dialog has three tabs - Date and Time, Date, and Time. The Date and Time is used to set the order of date and time using the Order drop down and Separator drop down is used to set the separator.




On Date tab, you can select the format of date the way you want. At the bottom, you will see preview of the date as well.




On Time tab, you can select the format of time the way you want.




Formatting a Formula for Date


What if you have a formula that has DateTime value and you want to format it? In that case, you do not see the Date and Time tab on the Format Editor.


In this situation, you rely on your own code.

ToText function comes handy to do all formatting. For example, I need a date formatting as following:




The following formula will do the trick:


ToText({MYFIELDNAME }, "dd-MMM-yyyy")


I can simply move around the formatting to generate other formats. For example, if I need the following format:


Mar 23, 2007


I simply change formula to the following:


ToText({MYFIELDNAME }, "MMM dd, yyyy")


And if I need format 03/23/07, I change formula to "MM/dd/yy".

Mahesh Chand
Mahesh Chand

C# Corner founder, 10-times Microsoft MVP, technical author, and software architect. Mahesh authored his first book, A Programmer’s Guide to ADO.NET in C# with APress at the age of 25. C# Corner is a memb... Read more



Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.

Trending up

Infragistics jQuery Controls