Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding "st, nd, rd to date format? 1

Status
Not open for further replies.

wld1957

Technical User
Feb 3, 2006
68
US
Is it possible to have crystal reports look at a date and add "st", "nd", "rd" or "th" to the day of the month. I can format the date from 01-01-06 to read 01, January 2006. I wanted it to be able to read, 01st, January 2006. or have it apply the proper ending for the date that is provided. Any help would be appreciated. Thanks in advance. Bill
 
You did not mention your version of Crystal, which is always important. The following will work in Crystal 8.5, assumming you already have your date appearing as "01, January 2006":

1) Format the field and select custom style and hit the customize button.
2) In the separators area, click on the X-2 button next to the first field and enter a formula:

Code:
if right(totext(day({Date}),0),1)="1" then "st, " else
if right(totext(day({Date}),0),1)="2" then "nd, " else
if right(totext(day({Date}),0),1)="3" then "rd, " else
"th, "

Replace {date} with your date field, obviously.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
Try:

if remainder(day({table.date}),10) = 1 and
day({table.date}) <> 11 then
totext({table.date},"dd")+"st, "+
totext({table.date}, "MMMM yyyy") else

if remainder(day({table.date}),10) = 2 and
day({table.date}) <> 12 then
totext({table.date},"dd")+"nd, "+
totext({table.date}, "MMMM yyyy") else

if remainder(day({table.date}),10) = 3 and
day({table.date}) <> 13 then
totext({table.date},"dd")+"rd, "+
totext({table.date}, "MMMM yyyy") else

totext({table.date},"dd")+"th, "+
totext({table.date}, "MMMM yyyy")

-LB
 
Thanks for the info, both formula's worked. I have both CR 7 and just upgraded to 11. This has saved me a great deal of time. Thanks for the assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top