Symptom
- How to customize the time format on x-axis of a bar chart to display "hh:mm am/pm"
- How to remove the ‘seconds’ portion from the time format on the x-axis to show am/pm instead
Environment
Crystal Reports 2008 (All Patch Levels)
Reproducing the Issue
- Create a Crystal Report against any database that has a datetime/time field
- Insert a chart on the Report Header (Insert->Chart)
- Right click the chart and go to ‘Chart Expert’
- In the ‘Data’ tab select the datetime/time field and move it to the ‘On Change of’ area
- Select the field which you want to show on the y-axis and move it to the ‘Show value(s)’ area
- Click ‘Ok’ and refresh the report
- Observe that the x-axis of the chart either displays the date if it is a ‘datetime’ field or the time in the format "hh:mm:ss" if it is a time field
- We would like to modify the x-axis by removing the ‘seconds’ portion from the time and display it in a customized format like "hh:mm am/pm"
Cause
This is ‘By design’. Crystal Reports will display the database field in any of the axes ‘as it is’
Resolution
The following work around helps in overcoming this situation if (hour({Time_Field})>12) then totext({Time_Field }, "hh:mm") + "pm" else if (hour({Time_Field })=12) and (minute({Time_Field })>0) then totext({Time_Field }, "hh:mm") + "pm" else if(hour({Time_Field })=12) and (minute({Time_Field })=0) and (second({Time_Field })>0) then totext({Time_Field }, "hh:mm") + "pm" else totext({Time_Field }, "hh:mm") + "am";
Keywords
Customize x-axis, bar chart, Crystal Reports , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To