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:
23-Mar-2007
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".