473,545 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1234
sixstringsk <th************ ****@yahoo.comw rites:
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.get Date()+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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 27 '08 #2
In comp.lang.javas cript message <a1b603ad-f021-4c69-b0ee-57b25e0dd3ae@27
g2000hsf.google groups.com>, Thu, 29 May 2008 20:43:48, sixstringsk
<th************ ****@yahoo.comp osted:
>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="JavaS cript1.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.getDa te() +7;
var year=time.getYe ar();
if (year < 2000) // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
// ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ - cannot find
// time.getFullYea r() 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.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
3192
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, top3, top4, top5, top6, top7, top8, top9, pricesmall, pricelarge FROM esperia WHERE productnumber = '$bestil'";
1
2577
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 access the recordset it displays the results, what the real issue is that the entry is not made into the database even though i use the Update...
9
2036
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 dtmCtl As Date Dim dtmTest As Date Me!cbxEndTime.Requery Me!cbxStartTime.Requery
8
4545
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 date in the form of mm/dd/yyyy: "); scanf ("%i/%i/%i", &date1.month, &date1.day, &date1.year); where date1 is a struct of type date, defined as:...
6
3770
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 one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps...
3
4979
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 : >************************************************************************ > <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _ > Public Function...
3
1617
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 since last contact I have where
5
1389
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 variables. My script's output is looking a bit strange... The file is sent from a server so changing it will be difficult. Nearly all of the data...
3
2194
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 that are SELECT elements (javascript-- one named arrivalcity and one named returncity). Basically they ask for a departure and return city and another...
0
7420
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...
0
7934
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...
1
7446
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...
1
5349
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...
0
3476
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...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
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
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
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...

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.