Click here to Skip to main content
13,007,176 members (60,115 online)
Click here to Skip to main content
Add your own
alternative version

Stats

31.3K views
1 bookmarked
Posted 23 Jul 2015

How to Change Date Format in Crystal Report

, 23 Jul 2015
Rate this:
Please Sign up or sign in to vote.
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 NameData typeColumn Specification
Lot_NointPrimary
Job_StatusVarcharNot Null
Issue_DateDateTimeNot Null
Customer_NameVarcharNot Null
Job_DescriptionVarcharNot 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.

  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.

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

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

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

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

  7. Now Press Main Report Preview button.

  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.

    https://www.codeproject.com/KB/gadgets/1012261/Ad.PNG

Thanks!

License

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

Share

About the Author

Mian Adnan
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionWhy not... Pin
Graham Lemon (UK)24-Jul-15 2:37
professionalGraham Lemon (UK)24-Jul-15 2:37 
QuestionNice Demo Pin
MozartHe23-Jul-15 15:15
memberMozartHe23-Jul-15 15:15 
AnswerRe: Nice Demo Pin
aarif moh shaikh23-Jul-15 21:58
professionalaarif moh shaikh23-Jul-15 21:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170628.1 | Last Updated 23 Jul 2015
Article Copyright 2015 by Mian Adnan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid