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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date to Words 2

Status
Not open for further replies.

Dominican1979

IS-IT--Management
Apr 30, 2008
108
US
Hello everyone,

Thank you for reading my post. I am trying to convert a date into words sort of. Here's an example:

11/09/2010 convert to: 9th of November 2010
01/01/2010 convert to: 1st of January 2010

I've tried the function MonthName(month) for the month and works and the year Year(year) but i'm not sure how to get the day with either the st, nd, rd or th, etc after the day. Your help will be greatly appreciated.

Crystal Reports XI
 
Dominican,

Here is a formula to give you an idea as to where to start. I would think you may want to build a separate formula field for Day & Year to avoid dealing with decimals and commas in the Day and Year (without making a nested replace).

Raw Formula:
Code:
If Day({Table.Field}) in [1,21,31] THEN
    Day({Table.Field}) & "st of " & MonthName(Month({Table.Field})) & " " & Year({Table.Field})
ELSE
If Day({Table.Field}) in [2,22] THEN
    Day({Table.Field}) & "nd of " & MonthName(Month({Table.Field})) & " " & Year({Table.Field})
ELSE
If Day({Table.Field}) in [3,23] THEN
    Day({Table.Field}) & "rd of " & MonthName(Month({Table.Field})) & " " & Year({Table.Field})
ELSE
    Day({Table.Field}) & "th of " & MonthName(Month({Table.Field})) & " " & Year({Table.Field})



Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
My apologies, I hit submit before complete... oops.

{@Day}
Code:
Replace(ToText(Day({Table.Field})),".00","")

{@Year}
Code:
Replace(Replace(ToText(Year({Table.Field})),".00",""),",","")

{@Final Display}
Code:
If Day({Table.Field}) in [1,21,31] THEN
    {@Day} & "st of " & MonthName(Month({Table.Field})) & " " & {@Year}
ELSE
If Day({Table.Field}) in [2,22] THEN
    {@Day} & "nd of " & MonthName(Month({Table.Field})) & " " & {@Year}
ELSE
If Day({Table.Field}) in [3,23] THEN
    {@Day} & "rd of " & MonthName(Month({Table.Field})) & " " & {@Year}
ELSE
    {@Day} & "th of " & MonthName(Month({Table.Field})) & " " & {@Year}

{@Final Display} will return "23rd of November 2010" for today.

Hope this helps.

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
totext(day({table.date}),"d")+
(
if day({table.date}) in 11 to 13 then
'th' else
(
select totext(day({table.date}),"00")[2]
case '1' : 'st'
case '2' : 'nd'
case '3' : 'rd'
default : 'th'
)
)

-LB
 
Thanks LB!

Much cleaner than my solution. [2thumbsup]

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
Hi lbass and MCuthill thank you so much for your help, both of your solutions work like a charm :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top