Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server / SQL-Server-2014

How to Change Date Format in Crystal Report

4.40/5 (5 votes)
23 Jul 2015CPOL1 min read 158.9K  
Using Microsoft Visual Studio Professional 2012, .NET 4.5 and Crystal Report Version regarding .NET 4.5 and VS 2012

Introduction

This tip will show you how to change date format in Crystal reports when you retrieve your records from database. I'm using SQL Server 2014 as the database engine.

Using the Code

Create a table in SQL Server having the following fields...

Field Name Data type Column Specification
Lot_No int Primary
Job_Status Varchar Not Null
Issue_Date DateTime Not Null
Customer_Name Varchar Not Null
Job_Description Varchar Not Null

If the field is passed in Crystal report as a DateTime, you will get a dialog that allows you to select all manner of different date/time formats, the date/time format by default looks like this 07/14/2015 12:00:00 AM/PM which is not a desired format. In this example, I'm going to change this (i.e., 07/14/2015 12:00:00 AM/PM) date format to i.e., 21-May-15.

  1. Right click on datetime field (i.e you are using in your Crystal report) and then select Find in Formulas.

    Image 1

  2. A formula workshop window will open. Now expand Formatting Formulas and also expand your report section which contains your date field. In my case, it is Details.

    Image 2

  3. In Details Section (i.e., search your date field), then right click on it and select New Formatting Formula.

    Image 3

  4. In this window, select Display String and press Use Editor Button.

    Image 4

  5. Type ToText(CDate({TableName.FieldName}), "dd-MMM-yy") in formula Editor window.

    Image 5

  6. Now Press Save and Close Button on top left of Format Formula Editor Window.

    Image 6

  7. Now Press Main Report Preview button.

    Image 7

  8. You can see the changed date format in Main Report Preview. You can also change date format string as "dd-MM-yy", "dd-MMM-yyyy", etc.

    Image 8

Thanks!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)