![]() |
Add ST/ND/RD/TH to DAY in DATE
I acquired this from joh6nn a year ago and now need one small addtion. This code produces the next meeting date based on one's local PC date. For the days, I need ST, ND, RD, TH added. For example, instead of "August 29", I need it to kick out "August 29th". Possible!?
Code:
<table border="0" cellpadding="2" cellspacing="0" width="100%" bgcolor="#EFEFEF"> |
I hope someone else has something less clunky. I couldn't even think of a good name for the function :)
Code:
function num_abbrev_str(num) { |
Graeme Hackston, thanks for the code. I couldn't tell you clunky from non...I just need results. :)
Anyway, I played around with it a little -- trying to get it to work -- but have been unsuccessful so far. Can you or someone else please explain how I'm supposed to include this in my JS? Better yet, can you just show me? I'll learn from it, I promise. |
Well it's clunky, anything with a bunch of else if and repeat statements is IMHO clunky.
I'd still like to see someone (maybe John) give you something better. For the time being this will work. If you want to capitalize them you can do that right in the function. Code:
|
By the way Gordo, I suspect you were having problems using it because the variable d is a number. The function requires a string. When you're having problems like this the easiest way I've found to see what's going on is to use typeof.
try this Code:
num = '22' |
Or, you can use typeof right in the function but this is adding yet another condition for the function to check.
If you use it like this you can remove .toString() from the function calls in Johns script. Code:
function num_abbrev_str(num) { |
Awesome...it works! :thumbsup:
|
Hmm, I don't think there's a non-clunky way of doing this. Here's a VBScript version that I use:
Code:
Function DateExt(ByVal intDay) |
This is definately clunky (kludgy?) but, fwiw, it might be useful to someone. :)
Code:
|
This almost looks like a good candidate for a coding challenge
title: De-clunk This Function So far, cheesebag is leading the pack :D |
Quote:
need to add... (make this the first check) Code:
|
How about this; still a little kludgy, but it works
Code:
function getNumberSuffix(dNum) |
I'm not sure why one so similar to mine was judged clunky... here we go.
Code:
Number.prototype.ordinal = function () { |
Quote:
|
Hmm, sounds like an interesting challenge - I'll throw together my own version:
Code:
Number.prototype.ordinal=function(){ |
| All times are GMT +1. The time now is 02:44 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.