Forum Discussion

vex's avatar
vex
Contributor
13 years ago

UTC Time Diffs not working.. haaalp :(

This problem is causing me to pull my hair out.



Assume this code:





 Log.Message "This account expires on " & sSQL(dba, strQuery, "expiration_date") & " (ETA: " & aqConvert.DateTimeToFormatStr(aqDateTime.TimeInterval(aqDateTime.Now, sSQL(dba, strQuery, "expiration_date")), "%#j days, %#H hours, %#M minutes, %#S seconds)")





This gets logged as:





This account expires on 3/5/2012 5:22:08 PM (ETA: 364 days, 4 hours, 3 minutes, 23 seconds)





It's reading the time from the Database as 3/5/2012 5:22:08 PM which is correct, but when doing the time conversion, it's not reading it right - it should be 4 hours 3 minutes, 23 seconds - NOT 364 days!  Is this because it's not returning a string, or because aqDateTime.Now is using local computer time while the time stored in the db is UTC time?

2 Replies

  • vex's avatar
    vex
    Contributor
    Quick Update - I've removed the SQL element of the conversion, but it still doesn't work!!



    Here is what I have for code - note that sSQL is a function that I wrote that handles the SQL stuff. 



    Arg 1: "w" or "r" for writing a value, or reading a query

    Arg 2: Database connection (dba is a variable with correct constring)

    Arg 3: Query to be run

    Arg 4: Field we're working with

    Arg 5: Value to be placed in field (only valid with "w" mode)





    expDate = sSQL("r", dba, "select * from users where id = '1'", "expiration_date", "") ' This returns 3/6/2012 1:27:07 AM



    postExpDate = aqDateTime.AddHours(expDate, 3) ' This properly returns 3/6/2012 4:27:07 AM into postExpDate



    Call sSQL("w", dba, "select * from users where id = '1'", "expiration_date", postExpDate)

    ' The above works, it writes 3/6/2012 4:27:07 AM into the database



    Log.Message "Expiration Date: " & postExpDate

    Log.Message "Expiration ETA: " & aqConvert.DateTimeToFormatStr(aqDateTime.TimeInterval(Now(), postExpDate), "%#j days, %#H hours, %#M minutes, %#S seconds")



    ' The above logs the following:

    '

    '    Expiration Date: 3/6/2012 4:27:07 AM

    '    Expiration ETA: 364 days, 9 hours, 55 minutes, 12 seconds

    '

    ' Which is not correct (Now() should be around 6:27pm central)

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I see it.



    You're using aqDateTime.TimeInterval which only deals with the TIME portion of the DateTime.  So, Now(), while it should include the date and time, actually is being formated down to a time only portion.  



    Try using, instead of aqConvert.DateTimetoFormatStr do



    aqConvert.TimeIntervalStr(aqDateTime.TimeInterval(Now(), postExpDate))




    You won't get your nice "days, hours, minutes, seconds" verbage but it should report more correctly.