Skip to Content

Crystal Reports 2008 -> Runtime settings for custom date type:

   For DateTime type Database or Formula field, we have different formatting options available in Crystal report.

Benefit:

Formula can be written to set the Date format dynamically (Run Time) based on requirement.  It can be based on parameter value or any database field. For example if Currency is a database field in the report, then based on its value if Currency= ‘USD’ then display date as 03/01/1999 and if Currency= ‘AUD’ then display date as 1999/01/03 .

Hence above criteria can be met using below mentioned information.

How To Use:

To set Custom format for Date field follow below mentioned steps:

1)    Place the Date field on any of the report section (Report Header, Page Header etc.) as per requirement.

2)    Right click on the Field, go to Format field and click on “Date and Time” Tab.

3)    Select Custom Style from the options provided under Style.

4)    Then click on Date Tab to do Date settings.

Note: 01 March 1999 is the example date value taken to display below options.

Following are the options available to set custom date values:

I)Date Type: This list lets you set following options:

a)    Choose one of the two default styles:

1) Windows default Long (Date will be displayed as Monday, March 01, 1999 [Note the other settings might affect its value.])

2) Windows default Short (Date will be displayed as 3/1/199 [Note the other settings might affect its value.])

b)    Choose Custom to create your own style in the Format Editor.

II)Calendar Type: If you are using Windows NT/95/98 your operating system may support more than one calendar type. For instance, your operating system may support a native calendar (Japanese), a Gregorian calendar (in the local language) and a Gregorian English calendar. If your operating system supports multiple calendar types you may use the Calendar Type list to select a calendar type for the date field.

III)Format: Month, Day, Year and Era can be set through this option.

a) Month: If you want to create a custom format for a date field object, use the below list to specify the way you want the report to print/display the month part of the date. The below options can be used in formula editor at runtime: (For e.g. If March is the Month then following Values will be returned)

      crNumericMonth (e.g. 3)  , crShortMonth (e.g. Mar) , crLongMonth (e.g. March), crLeadingZeroMonth (e.g. 03), crNoMonth (Nothing will be displayed)

It can be used in following manner:

 If Currency= USD then crNumericMonth

Else If Currency= AUD then crShortMonth etc…..

c) Day: If you want to create a custom format for a date field object, use this list to specify the way you want the program to print/display the day part of the date.

Following are the options available: crNumericDay (e.g. 1), crLeadingZeroDay (e.g. 01), and crNoDay (Nothing will be displayed)

c) Year: This conditional formatting formula must return one of the following Year Constants:

  crShortYear (99), crLongYear (1999),  crNoYear (Nothing will be displayed)

d) Era/Period type: Use the Era/Period Type list to select either a short or long era/period of time.

crShortEra,  crLongEra,  crNoEra

IV) Order: The order of display of DATE/MONTH/YEAR can be set through this option. If you want to create a custom format for a date field object, use these options to select the order in which you want the elements of the date to appear. Following are the options available:

crYearMonthDay (Prints the date in the order Year, Month, Day)

 crMonthDayYear (Prints the date in the order Month, Day, Year)

crDayMonthYear (Prints the date in the order Day, Month, Year)

V)Day of Week: When you are setting up a custom format for a date field object, if you want the name of the day (or an abbreviation of that name) to appear before the rest of the date, use this option to set the format for that name. Following options are available:    crShortDayOfWeek (e.g Mon), crLongDayOfWeek (e.g. Monday) and crNoDayOfWeek (Nothing will be displayed).

For Short Day and Long Day few more options can be set:

Sep: When you are setting up a custom format for a date field object, if you set the Leading Day Type property to short or long (so a day name or abbreviated day name appears before the date), you need to specify the character(s) you want to use to separate the name from the date itself. You do that in this box. Within practical limits, you can use as many characters as you need. For example,

To separate a date name from a date, you may use Comma  & Space (, ) as your separators. Type in the characters you want to use. The program modifies the sample date at the bottom of the dialog box as you do.

Encl: Use the Encl list to select parentheses or square brackets as an enclosure for date/time fields on your report.

 crDayOfWeekNotEnclosed,  crDayOfWeekInParentheses,  crDayOfWeekInFWParentheses,  crDayOfWeekInSquareBrackets,  crDayOfWeekInFWSquareBrackets

Position: Use the Position list to select either a Leading or a Trailing position.

 crLeadingDayOfWeek,  crTrailingDayOfWeek

VI)Separators: Following options are available:

a)Prefix: Use the Prefix box to create a prefix for dates in your date field, for example, DATE. The date will be displayed as DATE 01/03/1999.

b)First & Second: When you are setting up a custom format for a date field object, the program enables you to specify the separators, if any that you want to use to separate the date elements. For example,

If you are using a short format, all numbers, you may want to specify a hyphen (-) as the first separator and as the second separator as well (like 01-03-1999).

c)Suffix: Use the Suffix box to create a suffix that follows the dates in your date field, for example, DATE. The date will be displayed as 01/03/1999 DATE.

VII)Sample: This displays the sample date at the bottom to demonstrate the style chosen.

Note: The values can be chosen as STATIC from then dropdown or can be made DYNAMIC, by writing conditions in formula editor, available next to each option. 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply