Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating the number of days between dates

Status
Not open for further replies.

Philka

IS-IT--Management
Jun 19, 2001
11
0
0
US
I want to age an account...i.e. find the number of days
that has elapsed between a job being done (a date fields....chart.completed) and today's date (date()).
If I could write it to a variable (e.g. m.aged) I could
then use it in a report. Any ideas.
 
the date field can be used in math funcion
date()-m.date will give days between

CAUTION: if date was entered with set century off
(the default in fox26, you will have problems. system
dates inserted into field shoud be ok(most of the time)
if it is to be it's up to me
 
I have a similar problem. I used this simple code to calculate the difference between the current date and another date for several records in an Access table:

Option Explicit

Function GetElapsedDays(interval)
Dim days As Long
days = Int(CSng(interval))
GetElapsedDays = days & " Days"
End Function

This works fine. However, my problem comes while working at the query level. I get datatype mismatch error when attempting to place limits on the results (i.e., when trying to retrieve all records where the elapsed number of days is greater than 20 days). Any suggestions?
 
Hi

1. FPD has the problem relating to date for the current century. Example..
SET CENTURY OFF
DATE() wil display todays correct date.
But myDt=DATE()
@ 5,5 get myDate
READ
and now change anything in this myDate
? DTOS(myDate) it will show that it belongs to 102 year rather than 2002 year.
This is the long discussed CENTURY problem in FPD.

RESOLUTION.. SET CENTURY ON and do the above .. there will be no problem.


2. Now.. if you have allowed the date fields to be altered keeping the century off... errors would have got in..

SO what you can do is to rectify it.. by code.. using example..

REPLACE ALL chart.completed WITH ;
GOMONTH(chart.Completed,1200) ;
FOR YEAR(chart.completed) < 2000

From now on take care that the date field is accepted with proper centure.
AgeDays = DATE()-chart.completed will give correct answer in days.

:)


ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
Merry Christmas & Happy New Year [bigears] [party] [2thumbsup]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top