INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

work with end number

work with end number

(OP)
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??

RE: work with end number

How about;

CODE --> vBscript

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

RE: work with end number

(OP)
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.

RE: work with end number

(OP)
Could not get it to work. I will try more tomorrow when I have more time bigears

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close