Date difference in comments panel and runprepquery scripting

Hey all,

I found a problem where different times are displayed in the comments panel and when getting the same data out of the database with a query. Looking at different examples the date can be anywhere from 5 minutes to a half hour difference. Here is a screen shot of what I’m seeing:


Notice that the time in the comments panel is 20 minutes later than the last note added time at the top. These two times come from the same table but the last note added time is received with the following script:

try: if event.propertyName == "NoteFilter": search = event.source.NoteFilter tstamp = system.db.runPrepQuery("SELECT top 1 TimeStamp FROM notes WHERE TagName = ? ORDER BY TimeStamp desc", [search], "IgnitionDB") date = system.db.dateFormat(tstamp[0][0], "MMM d, yyyy hh:MM a") event.source.text = "Last Note Added: " + date except IndexError: event.source.text = "No Notes Found"

Did I do something wrong or is this an actual problem? The time difference is not always the same offset, it can vary by (so far) up to a half hour difference.

Well, which is the correct time? What is the time in the SQL database?

Doing a query from the Query browser, it appears that the time in the Comments panel is the correct time. I don’t understand why they would be different though… I just ran the exact same query that is in the script.

I guess then the date format function would be the culprit, no?

Yeah it could be the function. Try putting a print out before and after the dateFormat line:try: if event.propertyName == "NoteFilter": search = event.source.NoteFilter tstamp = system.db.runPrepQuery("SELECT top 1 TimeStamp FROM notes WHERE TagName = ? ORDER BY TimeStamp desc", [search], "IgnitionDB") print tstamp[0][0] date = system.db.dateFormat(tstamp[0][0], "MMM d, yyyy hh:MM a") print date event.source.text = "Last Note Added: " + date except IndexError: event.source.text = "No Notes Found"Let me know the results.

Ok, here’s what I found. Looks like it could be a function issue:


Oh I figured it out! Can’t believe I didn’t see this earlier. Your date format is wrong:

MMM d, yyyy hh:MM a

A capitol M is for the month not minute. The date format should be:

MMM d, yyyy hh:mm a

Change it and it should work just fine.

Ahhhh… yes, that fixed it. Wow, that made me feel like an idiot… :blush:

Thanks, Travis!