473,471 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

zero in front

How do I allways get day with two digits, not
var dd = d.getDate();
if (dd <10) dd = '0' + dd;

Aug 31 '07 #1
2 2423
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 31 '07 #2
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
Sep 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Steve | last post by:
Is there a way in PHP to zero fill an integer to a specified length? For instance, if I have a two digit number, and I want to zero fill it to four digits, is there a PHP function I can use? Or do...
6
by: david | last post by:
Hi, I have an application as follows: MySQL database Back-Eend linked to MS Access Front-End and ASP Web Application. I require users to enter Serial Numbers such as: 0105123567 (10...
2
by: Steve | last post by:
I have a database where I want to use an autonumber field to make SKUs for a new product when it is entered. Is there a way I can make the field zero fill to a certain length? For instance, if I...
0
by: John Mason | last post by:
Hi, I have developed an asp.net application that uses forms authentication. I have a local install and a remotely hosted install of the application. Intermittently the remote application falls...
4
by: Randall Parker | last post by:
I am designing a database schema. It happens to be in MySQL but I'm trying to keep it portable to other databases should the project grow. Anyway, suppose you have VARCHAR fields and will be...
3
by: keali | last post by:
for example: A1 = 123 A1=123000 <- final result A1 =1234 A1=123400<- final result A1=1 A1=100000<-final result
6
by: Patrick | last post by:
Hello All, Kind of new to PHP. I have an html form where a person inputs a date via a drop down select. How do I make php put a zero in front of the numbers 1-9 ie. 01 02 03 when writing to the...
15
by: angellian | last post by:
Sorry to raise a stupid question but I tried many methods which did work. how can I conserve the initial zero when I try to convert STR(06) into string in SQL statment? It always gives me 6...
3
by: Candace | last post by:
I have a program that performs calculations and displays a four digit number. Sometimes the calculation results in a number like 0854, but my program displays it as 854. How can I force the program...
8
by: Andrew Poulos | last post by:
In my limited testing with FF 2, IE 6 and Opera 9 when I divided a positive integer, that is less than 100, by 100 I get a leading zero in front of the decimal point. For example 80/100 gives...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.