In comp.lang.javascript message <9o********************@giganews.com>,
Fri, 31 Aug 2007 17:03:36, Randy Webb <Hi************@aol.composted:
>Sune said the following on 8/31/2007 2:54 PM:
>How do I allways get day with two digits, not
var dd = d.getDate();
if (dd <10) dd = '0' + dd;
The day will be returned as a number. The only way to get the leading
zero is to convert it to String and add it yourself as you are doing.
Incorrect. There are other ways. One can add 100 and use substring -
and, in VBScript, that seems the most efficient way.
The OP's code sometimes returns String and sometimes Number, which can
be disadvantageous. Consider
D = new Date(1111, 1, 6)
dd = D.getDate();
if (dd <10) dd = '0' + dd
S = (D.getMonth()+1) + dd
which gives 206. Change 6 to 16, and the result is 18.
In any case, if a page needs number-extension more than about twice, a
function should be used.
function LZ(x) { return (x>=10||x<0?"":"0") + x }
The FAQ seems silent on the subject.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Delphi 3? Turnpike 6.05
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.htmlnews:borland.* Guidelines