471,053 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,053 software developers and data experts.

Month number to string

What would be the best way to convert a month number to its corresponding
string? I.e, 3 -> 'March'. Is there a builtin function or must I use a
lookup table or something?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 20 '05 #1
2 9602

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:bn**********@chessie.cirr.com...
What would be the best way to convert a month number to its corresponding
string? I.e, 3 -> 'March'. Is there a builtin function or must I use a
lookup table or something?


Just use an array, e.g.:
var months = ['January', 'February', ....etc]

and then:
var monthString = months[new Date().getMonth()];
JW

Jul 20 '05 #2
JRS: In article <3f**********************@news.euronet.nl>, seen in
news:comp.lang.javascript, Janwillem Borleffs <jw@jwscripts.com> posted
at Tue, 21 Oct 2003 18:02:22 :-

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:bn**********@chessie.cirr.com...
What would be the best way to convert a month number to its corresponding
string? I.e, 3 -> 'March'. Is there a builtin function or must I use a
lookup table or something?


Just use an array, e.g.:
var months = ['January', 'February', ....etc]

and then:
var monthString = months[new Date().getMonth()];


That array will give April for the index 3. The OP, starting with the
conventional number for the month, must either subtract 1 or add a dummy
zeroth month : ['', 'Janu... .

The code given is correct, but for a different question.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by cover | last post: by
reply views Thread by larry | last post: by
22 posts views Thread by Stan | last post: by
8 posts views Thread by thunderbolt | last post: by
5 posts views Thread by Seb | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.