473,408 Members | 2,161 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,408 software developers and data experts.

Calculated Date

I have created a data form in which the user will enter in dates, and I wanted to know if there was a simple script that would allow me to take two date fields in the form and figure the days inbetween/ days left of the two dates. So I want something like a count down that will calculate the days left between the two enterd dates
Jul 24 '08 #1
3 1127
Brosert
57
i think you cam try something like:
Expand|Select|Wrap|Line Numbers
  1. var myDate1=new Date(); //todays date
  2. var myDate2=newDate(2008,6,6); //older date, you could also use "setFullYear"
  3. var temp=myDate1.getTime() - myDate2.getTime();
  4.  
  5. var day=24*60*60*1000; //convert milliseconds to days
  6.  
  7. var difference = temp/day;
  8.  
  9.  
Jul 24 '08 #2
RamananKalirajan
608 512MB
Hi I hope this code may help you if you are trying get the weekday between two user defined dates. Please ensure that the date format is dd-mon-yyyy.

[HTML]<Html>
<head>
<script language="javascript">
function changeVal(month)
{
if(month=="jan"||month=="Jan"||month=="JAN")
month=0;
if(month=="feb"||month=="Feb"||month=="FEB")
month=1;
if(month=="mar"||month=="Mar"||month=="MAR")
month=2;
if(month=="apr"||month=="Apr"||month=="APR")
month=3;
if(month=="may"||month=="May"||month=="MAY")
month=4;
if(month=="jun"||month=="Jun"||month=="JUN")
month=5;
if(month=="jul"||month=="Jul"||month=="JUL")
month=6;
if(month=="aug"||month=="Aug"||month=="AUG")
month=7;
if(month=="sep"||month=="Sep"||month=="SEP")
month=8;
if(month=="oct"||month=="Oct"||month=="OCT")
month=9;
if(month=="nov"||month=="Nov"||month=="NOV")
month=10;
if(month=="dec"||month=="Dec"||month=="DEC")
month=11;

return(month);
}
function findDiff()
{
var day1, day2;
var month1, month2;
var year1, year2;

value1 = document.getElementById('stDate').value;
value2 = document.getElementById('endDate').value;

day1 = value1.substring (0, value1.indexOf ("-"));
month1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
month1 = changeVal(month1);
year1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);

day2 = value2.substring (0, value2.indexOf ("-"));
month2 = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
month2 = changeVal(month2);
year2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);

var startDate = new Date(year1,month1,day1);
var endDate = new Date(year2,month2,day2);
var wrkdays=0;

while(startDate.getTime()<=endDate.getTime())
{
wrkdays++;
if(startDate.getDay()==0)
{
wrkdays--;
}
else if(startDate.getDay()==6)
{
wrkdays--;
}
else
{
}
var d = new Date(startDate.getTime() + 86400000);
startDate=d;
}
alert("Total Workdays = "+wrkdays);
}

</script>
</head>
<body>
<input type="text" id="stDate"><br/>
<input type="text" id="endDate"><br/>
<input type="button" value="calculate" onclick="findDiff()">
</body>
</html>[/HTML]

If you have any doubts pls ask yaar.

Regards
Ramanan Kalirajan
Jul 25 '08 #3
acoder
16,027 Expert Mod 8TB
That code could be shortened considerably, in particular the month code could be one line via an array. Also, the script language attribute is deprecated, use the type attribute instead.
Jul 29 '08 #4

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

Similar topics

1
by: douh | last post by:
I know that this is not the way, however I need to save certian calculated values so that they do not change over time, ie. new tax rates etc. This is for an invoice header and invoice subform. I...
1
by: Norbert Lieckfeldt | last post by:
MS Access 2002 here. I am just trying to set up a simple database for a friend who's an optician. Basically, all clients with address details, date of last eyetest and a drop-down combo box to...
2
by: Norbert Lieckfeldt | last post by:
I am setting up a database for a friend who's an Optician, using MS Access 2002. All seems to be working well, but I have hit a snag. There's a calculated field both in a form and a query which...
11
by: James Hallam | last post by:
I have read through all the past topics and couldn't find what I was after so... I am looking to store some calculated values (don't flame just yet, just read on!). I have an piece of code...
4
by: john | last post by:
I've searched google but can't find what I need. In my form I have a field Date Of Birth. Netxt to that field I would like to put a calculated field that shows the age of that particular person,...
0
by: trishbarker | last post by:
I've created a simple select query in Microsoft Access wherein I'm searching all records based on the "Final Payment Due Date". The Final Payment Due Date is a calculated expression based on two...
2
by: EdDale | last post by:
Hi and thanks in advance, I am using DMin and DMax to calculate date fields in a form. I need to use these calculated dates in another calculated field. example: =DMax("","B&MPayPeriod"," >=...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
3
by: Ciara9 | last post by:
I am having problems trying to update a field in a database using a field in a form. I currently have two fields, Today and Tomorrow in a table named Date. The Today field automatically defaults to...
1
by: Robert Bravery | last post by:
HI All, I am looking for a way to create some calculated columns in my typed dataset (VS 2005). This must be based on a datetime column in an SQL2005 table. The calculated column should return...
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
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,...
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,...
0
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...
0
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: 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...

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.