473,767 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date Month display problem

Jim
I have been using the javascript below on a web page since last August to
show the "Site updated" month only minus a month, which has been very
successful, but January is showing a "undefined 2004" message.
Help much appreciated
Jim

<<<var m=new Array(13);var n=new Date()

m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated
March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated
June";
m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
September";m[10]="Site updated October";m[11]="Site updated
November";m[12]="Site updated December"
document.write( m[n.getMonth()+0]+" "+n.getFullYear ())>>>
Jul 20 '05 #1
11 1833
Jim wrote:
I have been using the javascript below on a web page since last August to
show the "Site updated" month only minus a month, which has been very
successful, but January is showing a "undefined 2004" message.
Help much appreciated
Jim

<<<var m=new Array(13);var n=new Date()

m[1]="Site updated January";

[snip]

Arrays start from 0, not 1. You only need an array to hold 12 items, and
you need to number them from 0. At the moment, you are trying to write out
the string in m[0], which you haven't assigned to anything.

--
Jim Dabell

Jul 20 '05 #2
"Jim" <ji*@internet.c om> writes:
I have been using the javascript below on a web page since last August to
show the "Site updated" month only minus a month, which has been very
successful,
In making the users think you update the page frequently? :)
but January is showing a "undefined 2004" message.

<<<var m=new Array(13);var n=new Date()

m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated
March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated
June";
m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
September";m[10]="Site updated October";m[11]="Site updated
November";m[12]="Site updated December"
document.write( m[n.getMonth()+0]+" "+n.getFullYear ())>>>


getMonth returns the month number starting with 0 for January and ending with
11 for December. Your table has 1=>January, so it gives the previous month.
That means that you can change
m[12]="Site updated December"
to
m[0]="Site updated December"
and it will work for the month. The year from getFullYear is the current
one, so you will get December 2004 if that is all you do.
I recommend the following instead:
---
var monthName = [
"January","Febr uary","March"," April","May","J une","July",
"August","Septe mber","October" ,"November","De cember"];
var now = new Date();
now.setDate(1);
now.setMonth(no w.getMonth()-1);
document.write( "Site updated ",
monthName(now.g etMonth()),
" ",now.getFullYe ar());
---
We set the date back by one month, so the getMonth and getFullYear
refer to the same date. Setting the month to -1 will give December
of the previous year.

I set the date to the 1st to avoid problems when changing month.
Otherwise, setting the month back by one on the 31th of March would
give the 31th of February, which is normalized to give the 3rd of
March.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
"Jim" <ji*@internet.c om> wrote in message
news:3f******** *************** @news.dial.pipe x.com...
I have been using the javascript below on a web page since last August to
show the "Site updated" month only minus a month, which has been very
successful, but January is showing a "undefined 2004" message.
Help much appreciated
Jim

<<<var m=new Array(13);var n=new Date()

m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated June";
m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
September";m[10]="Site updated October";m[11]="Site updated
November";m[12]="Site updated December"
document.write( m[n.getMonth()+0]+" "+n.getFullYear ())>>>

How about this instead?

<html>
<head>
<title>SiteUpda ted.htm</title>
<script language="javas cript" type="text/javascript">
<!--
var m = new Array(11);
m[0] = "January";
m[1] = "February";
m[2] = "March";
m[3] = "April";
m[4] = "May";
m[5] = "June";
m[6] = "July";
m[7] = "August";
m[8] = "September" ;
m[9] = "October";
m[10] = "November";
m[11] = "December"
var n = new Date();
document.write( "Site updated " + m[n.getMonth()] + " " + n.getFullYear() );
// -->
</script>
</head>
<body>
</body>
</html>
Jul 20 '05 #4
"McKirahan" <Ne**@McKirahan .com> writes:
How about this instead? var m = new Array(11);
Why "11". You create an array with 11 empty slots, then put 12
elements into it. There is no need for that 11 at all.
m[0] = "January"; .... m[11] = "December"


It is shorter to just write:
var m = new Array("January" ,"February", .... ,"December") ;
(even shorter to write
var m = ["January",...," December"];
and it will only fail in browsers older than Netscape 4).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Jim
Hi Lasse
I like your recommended code but I can't get it to display at all.
I am very new to java and may well be overlooking
something simple.
Regards
Jim

"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:br******** **@hotpop.com.. .
"Jim" <ji*@internet.c om> writes:
I have been using the javascript below on a web page since last August to show the "Site updated" month only minus a month, which has been very
successful,
In making the users think you update the page frequently? :)
but January is showing a "undefined 2004" message.

<<<var m=new Array(13);var n=new Date()

m[1]="Site updated January";m[2]="Site updated February";m[3]="Site updated March";m[4]="Site updated April";m[5]="Site updated May";m[6]="Site updated June";
m[7]="Site updated July";m[8]="Site updated August";m[9]="Site updated
September";m[10]="Site updated October";m[11]="Site updated
November";m[12]="Site updated December"
document.write( m[n.getMonth()+0]+" "+n.getFullYear ())>>>


getMonth returns the month number starting with 0 for January and ending

with 11 for December. Your table has 1=>January, so it gives the previous month. That means that you can change
m[12]="Site updated December"
to
m[0]="Site updated December"
and it will work for the month. The year from getFullYear is the current
one, so you will get December 2004 if that is all you do.
I recommend the following instead:
---
var monthName = [
"January","Febr uary","March"," April","May","J une","July",
"August","Septe mber","October" ,"November","De cember"];
var now = new Date();
now.setDate(1);
now.setMonth(no w.getMonth()-1);
document.write( "Site updated ",
monthName(now.g etMonth()),
" ",now.getFullYe ar());
---
We set the date back by one month, so the getMonth and getFullYear
refer to the same date. Setting the month to -1 will give December
of the previous year.

I set the date to the 1st to avoid problems when changing month.
Otherwise, setting the month back by one on the 31th of March would
give the 31th of February, which is normalized to give the 3rd of
March.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #6
JRS: In article <3f************ ***********@new s.dial.pipex.co m>, seen
in news:comp.lang. javascript, Jim <ji*@internet.c om> posted at Sun, 4
Jan 2004 19:41:42 :-
I have been using the javascript below on a web page since last August to
show the "Site updated" month only minus a month, which has been very
successful, but January is showing a "undefined 2004" message.
Help much appreciated


Have you considered the simple and honest approach of typing the correct
date when the site is actually updated?

As it is, your approach of giving an automated lie implies that nothing
you write is trustworthy.

Read the FAQ.

--
© 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.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.
Jul 20 '05 #7
"Jim" <ji*@internet.c om> writes:
I like your recommended code but I can't get it to display at all.
I am very new to java and may well be overlooking
something simple.


First thing: It's Javascript, not Java. Java is a completely different
language.

And please don't top post.

There is a bug in the code, so no wonder it's not working. Here
is a fixed version:

<script type="text/javascript">
var monthName = [
"January","Febr uary","March"," April","May","J une","July",
"August","Septe mber","October" ,"November","De cember"];
var now = new Date();
now.setMonth(no w.getMonth()-1,1);
document.write( "Site updated ",
monthName[now.getMonth()],
" ",now.getFullYe ar());
</script>

(the square brackets after "monthName" had been replaced by parentheses)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #8
How about the old document.lastMo difed ?

Dr John Stockton <sp**@merlyn.de mon.co.uk> wrote in message news:<O+******* *******@merlyn. demon.co.uk>...
JRS: In article <3f************ ***********@new s.dial.pipex.co m>, seen
in news:comp.lang. javascript, Jim <ji*@internet.c om> posted at Sun, 4
Jan 2004 19:41:42 :-
I have been using the javascript below on a web page since last August to
show the "Site updated" month only minus a month, which has been very
successful, but January is showing a "undefined 2004" message.
Help much appreciated


Have you considered the simple and honest approach of typing the correct
date when the site is actually updated?

As it is, your approach of giving an automated lie implies that nothing
you write is trustworthy.

Read the FAQ.

Jul 20 '05 #9
JRS: In article <16************ *************@p osting.google.c om>, seen
in news:comp.lang. javascript, Kien <ca*********@ho tmail.com> posted at
Mon, 5 Jan 2004 18:12:59 :-
How about the old document.lastMo difed ?

Dr John Stockton <sp**@merlyn.de mon.co.uk> wrote in message news:<O+pfDQE16 W+$Ew
Xp@merlyn.demo n.co.uk>...

Have you considered the simple and honest approach of typing the correct
date when the site is actually updated?

As it is, your approach of giving an automated lie implies that nothing
you write is trustworthy.

Read the FAQ.

Please do not top-post.

Please do not over-quote.

Please read the FAQ.

--
© 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.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.
Jul 20 '05 #10

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

Similar topics

2
3381
by: Simon Wigzell | last post by:
My client has an annual calendar of events consisting of a record for each event, key field is the event date saved as a date type field. They would like the display to start with the current month, list to the end of the year then start the beginning of the year and list up to the current month. How does one retrieve data based on date? I guess I'd like something like : SELECT * FROM EVENTS WHERE ORDER BY Date Then :
2
1418
by: Fawke101 | last post by:
Hi there, I have a field in my SQL database - dtePurchased - and the values look like this - 24/03/2004, 35/03/2004 (UK format) I wish to display this field in a table on my ASP page by using the recordset object etc,,, The problem is, i only want to display the Month from each date. IE
3
6619
by: Melissa | last post by:
I have this table: TblProjectYear ProjectYearID ProjectYearStartDate ProjectYearEndDate The Project Year will always span across December 31; for example 9/1/04 to 6/30/05. How do I build a combobox based on this table that will display all the months between the StartDate and the EndDate for a given ProjectYearID and when a selection is made, the full date of the last day of the selected
3
4495
by: Bob Sanderson | last post by:
I have a PHP web page which uses a HTML form. I would like to enter dates into the date fields using a JavaScript calendar, similar to the way phpMyAdmin does. Can anyone recommend a JavaScript that will do this? Also, how can I add a button to a form to enter a NULL. Thanks in advance.
1
2621
osward
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >= current date. Otherwise, user have to waste time to page up the pages to find the current date 2. I got a script of simple calendar from the web that use mktime() to create links on the calendar Task I need to let user view data earlier than...
7
2102
by: creative1 | last post by:
Hello everyone. I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this. The problem is: I want to print account statement (or any other report) from VB form based on an entered date in the masked fields (dd/mm/yy). I am using one form to display five reports. I send date to display report after formatting it (m/dd/yy). When I enter date range like this in masked textbox (DD/MM/YY) ...
30
5716
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the database I have a table with Date/time column. The database is located on a machine that is set to dd/mm/yyyy also. When I enter date 7/1/08 (as in January 7, 2008), it stores it in the database as 1/7/08 instead of 7/1/08. Why is it like that...
3
1995
by: Paul | last post by:
Thanks to all the advice I have received but I seriously need more help (in more ways than one). The crux of the problem is that I need to insert a date into ClockStarts field and have access display another date into TargetDate field (plus 20 days but excluding Sat/Sun and holidays) If someone could give me the code to do this I would be forever in your debt. Thanks
1
3847
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt worked. Dates of particular year,month not displayed in that calender grids. i have collected that coding from online free resources. Here i have attached code for your reference. please do suggest me how do i display the calender date in grids in...
0
9571
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
9405
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
10013
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
9960
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
9841
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
8838
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
7383
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
6655
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3930
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 we have to send another system

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.