473,773 Members | 2,315 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
11 1835

U¿ytkownik "Jim" <ji*@internet.c om> napisa³ w wiadomo¶ci
news:3f******** *************** @news.dial.pipe x.com...
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.'

Vamat CIE certification:
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>
Lasse Reichstein Nielsen - lr*@hotpop.com
Jul 20 '05 #11
Lasse Reichstein Nielsen wrote:
"McKirahan" <Ne**@McKirahan .com> writes:
How about this instead?

var m = new Array(11);


Why "11". You create an array with 11 empty slots, [...]


Or an array with 1 non-empty slot containing a literal 11.
Depends on the ECMAScript implementation, so array literals
are the better way if the first element yields `true' for
!isNaN(...).
PointedEars
Jul 20 '05 #12

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
6621
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
2623
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
2104
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
5717
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
9454
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
10264
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10039
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
9914
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
8937
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
7463
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
6717
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();...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.