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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating correct day

Status
Not open for further replies.

megatron7

Programmer
Apr 18, 2005
11
0
0
US
If (txtResponseDate <> " ") Then
IssuedDate = txtDateIssued 'gets date from txtfield
ResponseDate = txtResponseDate 'gets date from txtfield
ResponseTime = ResponseDate - IssuedDate

Time1 = Format(ResponseDate, "hh:mm") 'get hour/min portion
Time2 = Format(IssuedDate, "hh:mm")

txtResponseTimeMin = Format(ResponseTime, "hh : mm")'displays hour/min

If (Time1 < Time2) Then
'txtResponseTimeDays = DateDiff("d", IssuedDate, ResponseDate)
Time1 = DateDiff("d", IssuedDate, ResponseDate)
Time2 = DateAdd("d", -1, Time1)
txtResponseTimeDays = Format(Time2, "d")
Else
txtResponseTimeDays = DateDiff("d", IssuedDate, ResponseDate)
End If
End If
I am trying to figure out how to get the right day. for example IssuedDate = 4/15/2005 5:08 PM and ResponseDate = 4/16/2005 5:07 PM. my result is 1 day, 23 hours and 59 min, when its suppose to be 0 days. i cant figure it out. please help
 
How are ya megatron7 . . . . .

Here's the difference broken down. I'm sure you can take it from here:
Code:
[blue]   Dim Dys As Long, Hrs As Integer, Mins As Integer
   
   diff = DateDiff("n", Me!txtDateIssued, Me!txtResponseDate)
   
   [purple]Dys[/purple] = Int(diff / 1440)
   diff = diff - 1440 * Dys
   
   [purple]Hrs[/purple] = Int(diff / 60)
   diff = diff - 60 * Hrs
   
   [purple]Mins[/purple] = diff

   [green]'Your Code[/green][/blue]

Calvin.gif
See Ya! . . . . . .
 
Another starting point:
MsgBox Int(ResponseDate-IssuedDate) & " days, " & Format(ResponseDate-IssuedDate," H \hour\s, N \mi\nute\s")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top