DateDiff function

digitaldon37

Active Member
Licensed User
Longtime User
Is there an equivalent to the VB DateDiff function in B4PPC, or am I missing something?

I wrote a quick sub to handle computing # days between two days, but was wondering if someone had done this already.

B4X:
Sub DateDiff (units, date1, date2)
   
   x=DateParse(date1)
   y=DateParse(date2)
   Select units
      Case "dd" 
         z=24*60*60
   
   End Select
   
   Return (y-x) / (z * 10000000)
   
End Sub
 

Rioven

Active Member
Licensed User
Longtime User

digitaldon37

Active Member
Licensed User
Longtime User
Hi

See this link... http://www.b4x.com/forum/tutorials/894-date-time.html


B4X:
Sub DateDiff (units, date1, date2)
   
   x=DateParse(date1)
   y=DateParse(date2)
   Select units
      Case "dd" 
         z=[B][COLOR="Blue"]cTicksPerDay[/COLOR][/B]
   End Select
   
   Return (y-x) / z
   
End Sub

Thanks! Here is a slight modification to handle hours and minutes
B4X:
Sub DateDiff (units, dt1, dt2)

If units="d" Then
   DateFormat ("mm/dd/yyyy")
   x=DateParse(dt1)
   y=DateParse(dt2)
   Return (y-x) / cTicksPerDay
End If

If units="h" Then
   TimeFormat("HH:mm")
   x=TimeParse(dt1)
   y=TimeParse(dt2)
   Return (y-x) / cTicksPerHour
End If

If units="m" Then
   TimeFormat("HH:mm")
   x=TimeParse(dt1)
   y=TimeParse(dt2)
   Return (y-x) / cTicksPerMinute
End If

If units="s" Then
   TimeFormat ("HH:mm:ss")
   x=TimeParse(dt1)
   y=TimeParse(dt2)
   Return (y-x) / cTicksPerSecond
End If


   
End Sub
   
   
End Sub
 
Last edited:
Top