PC Review


Reply
Thread Tools Rate Thread

Create calculated query for time difference

 
 
navin
Guest
Posts: n/a
 
      3rd Jan 2008
Hi,

In a list box i am displaying the request number and request date and
time for a user after reteriving from table. i need to add one extra
column which should display the ageing of the request by taking the
difference between request date and time and current date/time.

please tell me how this can be done.

thanks,
navin
 
Reply With Quote
 
 
 
 
Wayne-I-M
Guest
Posts: n/a
 
      3rd Jan 2008
Hi Navin

You could use a calculated column in the query the combo is based on

DifferenceateDiff("d", TableName!FieldName,Date())


--
Wayne
Manchester, England.



"navin" wrote:

> Hi,
>
> In a list box i am displaying the request number and request date and
> time for a user after reteriving from table. i need to add one extra
> column which should display the ageing of the request by taking the
> difference between request date and time and current date/time.
>
> please tell me how this can be done.
>
> thanks,
> navin
>

 
Reply With Quote
 
Ken Sheridan
Guest
Posts: n/a
 
      3rd Jan 2008
The following function allows you to return the difference between two
date/time values, either as, for instance, 2 days 3:12:58, or 51:12:58

Public Function TimeDuration( _
dtmFrom As Date, _
dtmTo As Date, _
Optional blnShowDays As Boolean = False) As String

Const HOURSINDAY = 24
Dim lngHours As Long
Dim strMinutesSeconds As String
Dim strDaysHours As String
Dim dblDuration As Double

dblDuration = dtmTo - dtmFrom

'get number of hours
lngHours = Int(dblDuration) * HOURSINDAY + _
Format(dblDuration, "h")

' get minutes and seconds
strMinutesSeconds = Format(dblDuration, ":nn:ss")

If blnShowDays Then
'get days and hours
strDaysHours = lngHours \ HOURSINDAY & _
" day" & IIf(lngHours \ HOURSINDAY <> 1, "s ", " ") & _
lngHours Mod HOURSINDAY

TimeDuration = strDaysHours & strMinutesSeconds
Else
TimeDuration = lngHours & strMinutesSeconds
End If

End Function

Paste the function into a standard module and in the list box's underlying
RowSource query call it with, to show the days:

TimeDuration([Request Date], Now(), True)

or to show it as total hours:

TimeDuration([Request Date], Now())

BTW, as someone pointed out recently, it does not cater for daylight saving
time either starting or ending within the range in question.

Ken Sheridan
Stafford, England

"navin" wrote:

> Hi,
>
> In a list box i am displaying the request number and request date and
> time for a user after reteriving from table. i need to add one extra
> column which should display the ageing of the request by taking the
> difference between request date and time and current date/time.
>
> please tell me how this can be done.
>
> thanks,
> navin
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create a calculated field in a query =?Utf-8?B?UGF0dHkgU3RvZGRhcmQ=?= Microsoft Access Queries 7 13th Apr 2007 01:13 AM
How to create a meeting in a difference time zone =?Utf-8?B?S25veHN0ZXI=?= Microsoft Outlook Calendar 0 21st Jun 2006 08:31 PM
Help with time difference query red skelton via AccessMonster.com Microsoft Access Queries 4 20th Jan 2006 11:54 AM
Query to create a calculated hypertext field John Schneider Microsoft Access 3 12th Oct 2005 02:47 AM
Time and Calculated Query - Help jj Microsoft Access 6 11th Jul 2004 02:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:33 AM.