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

Display today date day with the suffix after the day.

Status
Not open for further replies.

troop49

Programmer
Dec 17, 2009
17
US
Example:

17th day of September 2010

How can i display the 'th' after the 17
or the 'rd' for the 3rd etc...

 
In format date click customise

At the bottom you can change separators, opposite the day separator click the formula box.

If day(datefield) in [ 3, 23] then 'rd' else
If day(datefield) in [ 1, 21, 31] then 'st' else
If day(datefield) in [ 2, 22] then 'nd' else
'th'

Ian

 
If you want to return the entire string:

Code:
local stringvar v_day;
local stringvar v_result;

v_day := 

select day({@date}) 

case 1,21,31: "st"
case 2,22: "nd"
case 3,23: "rd"
case 4 to 20,24 to 30: "th";

v_result := totext(day({DateField}),"#",0) + v_day + " day of " + monthname(month({DateField})) + ", " + totext(year({DateField}),"#",0);

v_result

This would probably be a good opportunity for a custom function:

Code:
Function  (dateVar v1)

local stringvar v_day;
local stringvar v_result;

v_day := 

select day(v1) 

case 1,21,31: "st"
case 2,22: "nd"
case 3,23: "rd"
case 4 to 20,24 to 30: "th";


v_result := totext(day(v1),"#",0) + v_day + " day of " + monthname(month(v1)) + ", " + totext(year(v1),"#",0);

v_result
 
//
If day(CurrentDate) in [ 3, 23] then 'rd' else
If day(CurrentDate) in [ 1, 21, 31] then 'st' else
If day(CurrentDate) in [ 2, 22] then 'nd' else'th'


THis work beautifully.
THANK YOU!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top