473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Trouble With Date Code

Can anyone here help me with this...

I have a date code to display the date 7 days in the future— check it
out here : http://hidefsounds.com/date.html

The problem is that the day of the month doesn't reset when it's past
30/31 days... So currently it shows:

"May 36, 2008."

Any help would be appreciated. Thanks in advance.
Jun 27 '08 #1
2 1228
sixstringsk <th****************@yahoo.comwrites:
I have a date code to display the date 7 days in the future— check it
out here : http://hidefsounds.com/date.html

The problem is that the day of the month doesn't reset when it's past
30/31 days... So currently it shows:

"May 36, 2008."
Use a Date object when you work with dates. It prevents you from
creating non-existing dates by wrapping, e.g., 36th of May into
5th of June.

var d = new Date(); // today
d.setDate(d.getDate()+7); // 7 days later
// format as string before displaying

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 27 '08 #2
In comp.lang.javascript message <a1b603ad-f021-4c69-b0ee-57b25e0dd3ae@27
g2000hsf.googlegroups.com>, Thu, 29 May 2008 20:43:48, sixstringsk
<th****************@yahoo.composted:
>Can anyone here help me with this...

I have a date code to display the date 7 days in the future— check it
out here : http://hidefsounds.com/date.html

The problem is that the day of the month doesn't reset when it's past
30/31 days... So currently it shows:

"May 36, 2008."

Any help would be appreciated. Thanks in advance.

Code which is that short should be posted to the newsgroup, for easier
handling.

<QUOTE>
<script language="JavaScript1.2">
// ^^^^^^^^^^^^^^^ Deprecated.
// text/javascript preferred, or nothing.
<!-- Begin
// superfluous
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";

// var months = ["January", ... "December"] better, and zero-based

var time=new Date();
var lmonth=months[time.getMonth() + 1];
// then no need to add 1
var date=time.getDate() +7;
var year=time.getYear();
if (year < 2000) // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - cannot find
// time.getFullYear() is better
document.write("" + lmonth + " ");
// ^^^^ superfluous
document.write(date + ", " + year + "");
// End -->
// superfluous

</script>
</QUOTE>

Obviously the month will over-range, as you have done nothing to make it
do otherwise.

You should follow Lasse's advice, but ignore the erroneous signature.

Otherwise

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 27 '08 #3

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

Similar topics

5
by: Andreas Paasch | last post by:
I'm having trouble with the implode function and need some help here. I've been reading at php.net but that didn't solve my problem. I'm having the below code: $query = "SELECT top1, top2,...
1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
9
by: deko | last post by:
What is it with these dates? What are they so much trouble? All I want to do is subtract an hour, but not if that makes dtmTest less than dtmClt. Dim dtmStart As Date Dim dtmEnd As Date Dim...
8
by: Eric A. Johnson | last post by:
I am using scanf (from stdio.h) and having trouble inputting a date. I want the user to be able to input a date in the format mm/dd/yyyy. I use the following: printf ("Please enter your first...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
3
by: lostdawg | last post by:
Hi, I am having trouble with the following query. I need to sort from a list of contacts the last date each was contacted. This is to be represented in days so for instance: 0-42 days...
5
by: g0uki | last post by:
Hi all, i hope you can help, I'm having some trouble getting all the data from a file, well just the date and time entries. I'll be doing operations on the data so would like to store it within...
3
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.