473,908 Members | 8,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

lengths?

Hey, I'm completely new to javascript, but I've had some experience
with Python (I know they're completely different; I don't want anyone
replying just to say so). I'm having a problem with getting the current
date and manipulating it as I need.

What I'm doing is a directory with a bunch of HTML files of the name
"DaysMM_DD.html ", where MM and DD are 2 digit months and days
respectively. I want to get today's file, and am having trouble with
the code, seen below (with a couple stat markers):

=============== ===========
<SCRIPT language=javasc ript>
<!--
var stats=""
var date=new Date();
var day=date.getDay ();
var month=date.getM onth();
if (month.length== 1){var full_month="0"+ month; var
stats=stats+"<B R>month was too short\n";}else{ var full_month=mont h; var
stats=stats+"<B R>month was the right length\n";};
if (day.length==1) {var full_day="0"+da y; var stats=stats+"<B R>day was
too short\n";}else{ var full_day=day; var stats=stats+"<B R>day was the
right length\n";};
var URL="Days"+full _month+"_"+full _day+".html";
document.write( "<H1 align=center><A HREF=\""+URL+"\ ">This
Way!</A></H1>");
document.write( stats)
-->
</script>
=============== ===========

1. I'm getting the wrong date. It might be my browser has the wrong
date, but I doubt that.
2. The length comparisons seem to be going wrong. I tried before to do
month.string.le ngth, but that seemed to be the wrong way.

What am I doing wrong???

Feb 5 '06 #1
12 1389
Du**********@gm ail.com wrote:
Hey, I'm completely new to javascript, but I've had some experience
with Python (I know they're completely different; I don't want anyone
replying just to say so). I'm having a problem with getting the current
date and manipulating it as I need.

What I'm doing is a directory with a bunch of HTML files of the name
"DaysMM_DD.html ", where MM and DD are 2 digit months and days
respectively. I want to get today's file, and am having trouble with
the code, seen below (with a couple stat markers):

=============== ===========
<SCRIPT language=javasc ript>
<!--
var stats=""
var date=new Date();
var day=date.getDay ();
var month=date.getM onth();
if (month.length== 1){var full_month="0"+ month; var
stats=stats+"<B R>month was too short\n";}else{ var full_month=mont h; var
stats=stats+"<B R>month was the right length\n";};
if (day.length==1) {var full_day="0"+da y; var stats=stats+"<B R>day was
too short\n";}else{ var full_day=day; var stats=stats+"<B R>day was the
right length\n";};
var URL="Days"+full _month+"_"+full _day+".html";
document.write( "<H1 align=center><A HREF=\""+URL+"\ ">This
Way!</A></H1>");
document.write( stats)
-->
</script>
=============== ===========

1. I'm getting the wrong date. It might be my browser has the wrong
date, but I doubt that.
2. The length comparisons seem to be going wrong. I tried before to do
month.string.le ngth, but that seemed to be the wrong way.

What am I doing wrong???

confusion between day (monday, tuesday...) and date (01, 02...31)

Try this:

<SCRIPT language=javasc ript>
<!--
var today=new Date();
var theday=today.ge tDate();
if (theday<10) {zero="0";}
else {zero="";}
var themonth=today. getMonth();
tabmonth = new
Array("01","02" ,"03","04","05" ,"06","07","08" ,"09","10","11" ,"12");
var URL="Days"+zero +theday+"_"+tab month[themonth]+".html";
document.write( "<H1 align=center><A HREF="+URL+">Th is Way is
better!</A></H1>");
-->
</script>

for today, it should return "Days05_02.html " where 05 is the date and 02
the month (february)

Ignace de Witte
http://www.reunionislandguns.com
Feb 5 '06 #2
Thanks. Seems to have worked.

Feb 5 '06 #3
JRS: In article <11************ **********@z14g 2000cwz.googleg roups.com>
, dated Sat, 4 Feb 2006 18:59:14 remote, seen in
news:comp.lang. javascript, Du**********@gm ail.com posted :
Hey, I'm completely new to javascript,
If you intend to continue posting here, you need to find out how to post
(and write) readily-readable javascript, and how to format a News reply
when using Google (though it would be better to use a proper
newsreader). Read the newsgroup FAQ.

What I'm doing is a directory with a bunch of HTML files of the name
"DaysMM_DD.htm l", where MM and DD are 2 digit months and days
respectively . I want to get today's file, and am having trouble with
the code, seen below (with a couple stat markers):

============== ============
<SCRIPT language=javasc ript> // deprecated form
<!--
var stats=""
var date=new Date();
var day=date.getDay (); // Day of Week, non-ISO form
var month=date.getM onth(); // 0..11
... 1. I'm getting the wrong date. It might be my browser has the wrong
date, but I doubt that.
Easily checked by document.write( date) though that may give the date
in FFF.
2. The length comparisons seem to be going wrong. I tried before to do
month.string.l ength, but that seemed to be the wrong way.
Using String(month).l ength will give what you want. Most people
add a leading zero after testing numerically against 9 or 10, but
testing length is quite sensible especially in the general case where
there is a risk that the input is outside the expected range.

If you need to add a leading zero often enough (>2-4 times IMHO), better
to write a function for it; I use

function LZ(x) { return (x>=10||x<0?"": "0") + x }

which always returns a String.
What am I doing wrong???


Guessing.
with (new Date())
filename= "Days" + LZ(getMonth()+1 ) + "_" + LZ(getDate()) + ".html"

should suffice.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Feb 5 '06 #4
Thanks for explaining how evil this Javascript support group is. I'll
remember to avoid it at all costs.

Feb 7 '06 #5
Du**********@gm ail.com said the following on 2/6/2006 7:10 PM:
Thanks for explaining how evil this Javascript support group is.
Getting good answers is evil? Wow, didn't know that. But in any event,
this is *not* a "support group". It is a "discussion group". If you get
an answer, great. That is *not* its purpose though.
I'll remember to avoid it at all costs.


Don't make such wild promises, they might bite you later.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 7 '06 #6

Randy Webb wrote:
Du**********@gm ail.com said the following on 2/6/2006 7:10 PM:
Thanks for explaining how evil this Javascript support group is.
Getting good answers is evil?


I was referring to the person who was telling me not to use Google
Groups.
Wow, didn't know that. But in any event,
this is *not* a "support group". It is a "discussion group". If you get
an answer, great. That is *not* its purpose though.
So direct me to a support group. It seems from the faq that this is
intended to be a support group.
I'll remember to avoid it at all costs.


Don't make such wild promises, they might bite you later.


Not too difficult to keep, since I don't use javascript so much.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Feb 7 '06 #7
Lee wrote on 07 feb 2006 in comp.lang.javas cript:
You're not a customer. You're not always right.


Lee, but you are!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 7 '06 #8
Lee said the following on 2/7/2006 10:08 AM:
Du**********@gm ail.com said:
Thanks for explaining how evil this Javascript support group is. I'll
remember to avoid it at all costs.


You should avoid using Google to post to this (or any other)
group,


Not sure I agree with that. You should avoid Google Groups unless you
understand it's pitfalls and how to get around them.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 7 '06 #9
JRS: In article <fe************ ********@comcas t.com>, dated Tue, 7 Feb
2006 12:31:05 remote, seen in news:comp.lang. javascript, Randy Webb
<Hi************ @aol.com> posted :
Lee said the following on 2/7/2006 10:08 AM:
Du**********@gm ail.com said:
Thanks for explaining how evil this Javascript support group is. I'll
remember to avoid it at all costs.


You should avoid using Google to post to this (or any other)
group,


Not sure I agree with that. You should avoid Google Groups unless you
understand it's pitfalls and how to get around them.


The evidence is that anyone with enough intelligence to use Google
Groups correctly has enough intelligence to benefit from using a well-
written standards-compliant newsreader.

That means a newsreader that can, as supplied, get SigSeps and dates
right.

Granted, some people are prevented by circumstances from using a proper
newsreader, some or all of the time.

YGCIB.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Feb 8 '06 #10

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

Similar topics

9
2149
by: superprad | last post by:
"X-No-Archive: yes" what I am looking for is 1. To create a list of different words of various lengths(1-15) using A-Z,a-z,0-9 and punctuations.Basically anything that could be found on a text document. 2. The words formed need not be meaningful .FOr example 'ajf' or 'fcjgdtfhbs' or even 'gfdew!' or '#bang.' would be a valid entry in the
2
1160
by: superprad | last post by:
X-No-Archive: yes what I am looking for is 1. To create a list of different words of various lengths(1-15) using A-Z,a-z,0-9 and punctuations.Basically anything that could be found on a text document. 2. The words formed need not be meaningful .FOr example 'ajf' or 'fcjgdtfhbs' or even 'gfdew!' or '#bang.' would be a valid entry in the list.
8
4738
by: Hal Vaughan | last post by:
Is there a maximum length for Javascript program lines? What about strings? Is there a limit on string length? I found some references that said the maximum string length was 256 characters, but I have a program that created a string of over 25,000 characters (the browser was Konqueror). Are there limits on these lengths? If I require a newer browser for the program I'm writing, would that change the situation?
8
1339
by: bozzzza | last post by:
Is it possible to tell sql server to cast to a datatype and set the field length to a variable. e.g. :- declare @flen int set @flen = 10 select (cast somefield as char(@flen) newfield) into newtable
0
1026
by: Jeff Rush | last post by:
There is a discussion going on regarding how long the presentations should be for PyCon 2006. In the past the sessions have been 20 minutes of talk, 5 minutes of questions and 5 minutes to change rooms, grouped into 90-minute timeslots, with a 30-minute break btw each 90-minutes. There were comments last year that that 20-minutes was too short to cover much material, so there is a push to extend that to 50-minutes of talk, 5 minutes Q/A...
9
6218
by: Chris Bowlby | last post by:
Hi All, I've noticed that in the pg_type system table, there is a data type called "name", would that represent the definition of the table name space, including the max length a talbe name space could be? If so where would I find the same definition for the max name space for a sequence, or index... -- Chris Bowlby <excalibur@hub.org>
7
5651
by: arkobose | last post by:
hey everyone! i have this little problem. consider the following declaration: char *array = {"wilson", "string of any size", "etc", "input"}; this is a common data structure used to store strings of any lengths into an array of pointers to char type variable. my problem is: given the declaration
1
2702
by: Anne | last post by:
I am creating text box controls "on the fly" for strings of varying lengths. I want to make the text box size match the size of the string. How do I convert the length of the string (len) to pixels, which is required by Size. The Font is sized in Point. aTextBox.Size = new System.Drawing.Size((len * ??? ), 20);
4
9627
by: chy1013m1 | last post by:
In Java, one can do the following: int array = {{1,2,1}, {1}, {0,0,0,0,0,0,0,-1}}; How can one declare such array in C++/C without using various new operators individually to each row indicies? (with a ptr-ptr) Also, I've noticed that it works for char array: char *charArray = {"123456", "1515", "1"}; compiles on mingw32 but int *intArray = {{1,2,1,2,1}, {11}, {0}}; wouldn't compile. thanks =]
3
891
by: andrews | last post by:
I have to add several strings to a listbox. add str1 & str2 add str3 & str4 (new line) ..... the strings str1 and str2 have different lengths and i want that the strings str2 and str4 are aligned in the listbox I tried to add spaces to shorter strings to have the same lengths for str1 and str2 but there is no alignment for str2 and str4 Take the spaces more place then other chars or is the fontsize importent?
0
10031
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9875
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10913
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10536
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9721
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8094
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5930
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4336
muto222
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.