473,466 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Create 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 2620
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
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...
12
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...
18
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
1
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...
2
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...
1
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...
0
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...
5
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...
1
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
1
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.