Kod:
Option Compare Database
Option Explicit
Public Function DtDiff(ByVal sdate As Date, ByVal edate As Date, Optional pItems As String = "dhns") As String
Dim timehold, xdays, xmins, xhrs, xsecs
Dim strChar As String
Dim strHold As String
Dim strKeep As String
Dim n As Integer
timehold = DateDiff("s", sdate, edate)
xdays = timehold \ 86400
xhrs = timehold \ 3600 - (xdays * 24)
xmins = timehold \ 60 - (xhrs * 60) - (xdays * 24 * 60)
xsecs = timehold Mod 60
strHold = "dhns"
For n = 1 To 4
strChar = Mid(strHold, n, 1)
If InStr(pItems, strChar) = 0 Then
If strChar = "d" Then
xhrs = xhrs + (xdays * 24)
xdays = 0
ElseIf strChar = "h" Then
xmins = xmins + (xhrs * 60)
xhrs = 0
ElseIf strChar = "n" Then
xsecs = xsecs + (xmins * 60)
xmins = 0
ElseIf strChar = "s" Then
xsecs = 0
End If
End If
Next n
For n = 1 To Len(pItems)
strChar = Mid(pItems, n, 1)
If strChar = "d" Then
strKeep = strKeep & xdays & " gün" & IIf(xdays <> 1, " ", "") & " "
ElseIf strChar = "h" Then
strKeep = strKeep & xhrs & " saat" & IIf(xhrs <> 1, " ", "") & " "
ElseIf strChar = "n" Then
strKeep = strKeep & xmins & " dakika" & IIf(xmins <> 1, " ", "") & " "
ElseIf strChar = "s" Then
strKeep = strKeep & xsecs & " saniye" & IIf(xsecs <> 1, " ", "") & " "
End If
Next n
DtDiff = Trim(strKeep)
End Function