473,598 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating a date range

Claus Mygind
571 Contributor
My date calculation do not seem to work out. I have a list box with a character string value of dates ie: 03/28/2009. I want to create a date range for the week. So I would like to get the starting and ending date for this week. In the code below is what I attempted, but the results I got were Tuesday Apr 28 and Wednesday Apr22. what am I doing wrong:

Expand|Select|Wrap|Line Numbers
  1.  
  2. var cW = document.getElementById('resetNonUnionTime').value; 
  3. var dEnd = new Date( cW.substr(6,4),cW.substr(0,2),cW.substr(3,2) ); 
  4. var dStart = new Date( dEnd );
  5. dStart.setDate(dStart.getDate()-6); 
  6. alert(cW+"\n"+dEnd+"\n"+dStart);
  7.  
Here is the actual results from the alert box:
03/28/2009
Tue Apr 28 2009 00:00:00 GMT-0500 (Central Daylight Time)
Wed Apr 22 2009 00:00:00 GMT-0500 (Central Daylight Time)
Apr 3 '09 #1
3 2632
Claus Mygind
571 Contributor
Well it seemed to work when I removed the substr on the cW variable. But my question now is. Is this a reliable method of doing the date calculation? I am using Firefox. Will this method work with other browsers as well?

Expand|Select|Wrap|Line Numbers
  1.  
  2. var cW = document.getElementById('resetNonUnionTime').value; 
  3. var dEnd = new Date( cW ); 
  4. var dStart = new Date( cW ); 
  5. dStart.setDate(dStart.getDate()-6); 
  6. alert(cW+"\n"+dEnd+"\n"+dStart);
  7.  
Apr 3 '09 #2
acoder
16,027 Recognized Expert Moderator MVP
The month is 0-based, so just subtract 1 from it.
Apr 3 '09 #3
Claus Mygind
571 Contributor
Thanks that explains it.
Apr 6 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5207
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
12
23713
by: Anthony Robinson | last post by:
Is anyone aware of a function (system or user defined) that will calculate business days? For instance: I have a column in as table called DATE. I want to be able to add five business days to that date and come up with a new date. Is that possible. Also, is there anyway that DB2 can be aware of holidays? Maybe load them onto the server in some type of reference file or something. I ask these questions because I'm working on a banking...
18
38222
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
1
1399
by: David | last post by:
Hi, I have a problem with returning a value from an external function..... My asp page is basically a list taken from a database. A date record is written from the DB, then all the recordslinked to that date are listed, then the next date, then the next series of records, i.e.
2
2085
by: Carl | last post by:
Hi, I have a query that produces an output similar to the sample shown below. These records are based on certain criteria and a date range selected from a form. I need to create some kind of calcualtion or record manipulation to do the following: I need to subtract dates from one another, for example for ID 1 I want to find the difference between 24-Jun-04 and 25-Jan-06 for the 2 applications for Person1.
1
2460
by: josecruz | last post by:
I have created a main report, which is controlled with a date range parameter from the main form. The report has several sub reports, which perform calculations (counts and averages at the subreport level) based on the date range from the main form. My question or problem is that I have to calculate a percentage based on the result of two of the subreports. I created a text box on the main report and I enterd the following to calculate the...
0
1407
by: babujigodem | last post by:
Yes i have the function First of all calculate the week number of the desired date and apply the following function function retornarRangoDiasxSemana($anno, $semana) { // Determinar el día del inicio del año $anno = date('Y',mktime(0, 0, 0, 1, 1, $anno)); // 0 para el domingo a 6 para el sábado $diaInicial = date('w',mktime(0, 0, 0, 1, 1, $anno));
5
2728
FOE2272
by: FOE2272 | last post by:
I am working on a report that will Sum the Sales (Bid Price Field) that are still Active (Bid Status Field) for the past 1 Week, 2 Weeks, 3 Weeks, 4 Weeks, 30 Days, 60 Days, 90 Days, 120 Days, 150 Days,
1
2800
by: Del | last post by:
I have a parameter query that requires the user to enter a Start Date: and End Date: and pull data between that date range. I am currently using the following parameter; Select * From mytable Where between and This query will always be run on a Monday and the start date will always be the previous Sunday. The end date will be the previous
0
7894
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,...
1
8046
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
8262
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
6711
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
5847
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
5437
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
3894
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...
1
1500
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
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.