DateDiff function

Discussion in 'Questions (Windows Mobile)' started by digitaldon37, Dec 10, 2008.

  1. digitaldon37

    digitaldon37 Active Member Licensed 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.

    Code:
    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
     
  2. Rioven

    Rioven Active Member Licensed User

    Hi

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


    Code:
    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
     
  3. digitaldon37

    digitaldon37 Active Member Licensed User

    Thanks! Here is a slight modification to handle hours and minutes
    Code:
    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: Dec 10, 2008
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice