Android Question Excel date to ticks

oldeast

Active Member
Licensed User
Longtime User
B4X:
Dim DateDiff As Long=25569
        Dim  DaySecs As Long=86400
        Dim val As Long
        If IsNumber(XLList.Get(3))  Then
            val=XLList.Get(3)
            val=  (XLList.Get(3) - DateDiff) * DaySecs
            Log(val)
            Log(DateTime.Date(val))
            Return
Date is 21/12//2011 (40898) in excel and converts to 1324425600 ticks which is correct but logs as 1/16/1970
what did I do wrong..thanks
 
Last edited:

oldeast

Active Member
Licensed User
Longtime User
B4X:
Dim ExcelUnixDiff As Long=25569
        Dim  DaySecs As Long=86400
        Dim val As Long
        If IsNumber(XLList.Get(3))  Then
            val=XLList.Get(3)
            val=  (XLList.Get(3) - DateDiff) * DaySecs
            Log(val)
            val=DateUtils.UnixTimeToTicks(val)
            DateTime.DateFormat="dd-MMM-yyyy"
            Log(DateTime.Date(val))
I was not converting Unix time to ticks
The ExcelUnixDiff variable is the number of days between Jan 1 1900 and Jan 1 1970
XLList.get(3)=21/12//2011 (40898) in Excel
log 1324425600
log 21-Dec-2011

B4X:
Public Sub ExcelDateToString(t As Long) As String
    Dim ExcelUnixDiff As Long=25569             'days between Jan 01 1900 and Jan 01 1970
    Dim  DaySecs As Long=86400             'number of seconds in a day
    Dim val As Long
    val=  (t - ExcelUnixDiff) * DaySecs
    val=DateUtils.UnixTimeToTicks(val)
    DateTime.DateFormat="dd-MMM-yyyy"
    Return(DateTime.Date(val))
 
End Sub
 
Last edited:
Upvote 0
Top