473,804 Members | 4,217 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 2644
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
5227
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
23873
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
38251
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
1
1407
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
2096
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
2471
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
1420
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
2741
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
2812
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
9707
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9585
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
10586
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
10323
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
9161
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
7622
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
6856
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();...
1
4301
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
3
2997
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.