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

work with end number

Status
Not open for further replies.

penguinspeaks

Technical User
Nov 13, 2002
234
US
Hello gang, I hope all is well in your world.

I want to be able to work with the end digit in the days of the year, and have an if/then to make it be a nd, st, rd, ect.

So it would read "This is the 222nd day of the year."
I have the code to get the day of the year using
Code:
<%=DateDiff("d",DateSerial(Year(Now),1,1),Date)%>
I just need to add the suffix variable somehow.

Any ideas??
 
How about;

Code:
Function addOrdinalString(p_iVal)
  sNum = cStr(p_iVal)
  iNum = p_iVal mod 10
  select case iNum
    case 1
      sOrd = "st"
    case 2
      sOrd = "nd"
    case 3
      sOrd = "rd"
    case else '4,5,6,7,8,9,0
      sOrd = "th"
  end select
  ' deal with the teens
    if p_iVal > 10 and p_iVal <20 then sOrd = "th"
  sNum = sNum & sOrd
  addOrdinalString = sNum
End Function

It was only intended to handle 1 to 31 (for obvious reasons) but should tweak for > 100 upwards with a bit of code to strip off the first character (the hundreds) from p_iVal if > 99, add the ordinal, then concatenate the leading character back on.

I would do that myself but I don't have a Windows machine to test on, plus it's 4:AM and I'm running on tea and Ginger Nuts.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
lol, get some sleep dude!!

I will try this in the morning as I am heading to bed. Since the stroke, I sleep at least 10 hours a night.

Thanks a ton and I will let you know of the outcome.
 
Could not get it to work. I will try more tomorrow when I have more time [bigears]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top