jcpetu Posted December 9, 2019 Share Posted December 9, 2019 Hi people, I'm tryng to convert SQLite timestamp to readable human format but I get 00:00:00 instead of the known value. Here my code if someone could help: #include <Constants.au3> #include <Date.au3> Local $EPOCH = 13215743943956926 / 1000000; 16/10/2019 08:59:03 p.m. Local $EPOCHinHHMMSS= Convert($EPOCH) ConsoleWrite($EPOCHinHHMMSS) MsgBox($MB_SYSTEMMODAL, '', ConvertToReadable($EPOCHinHHMMSS)) Func ConvertToReadable($iEpoch) Local $difference = _DateDiff("s", "1601/01/01 00:00:00", "1970/01/01 00:00:00") Return Convert(_DateDiff("s", $iEpoch, $difference)) EndFunc ;==>_EpochToDate Func Convert($t) $h = Floor($t / 3600) $m = Floor(($t - $h * 3600) / 60) $s = Mod($t, 60) Return StringFormat('%02i:%02i:%02i',$h, $m, $s) EndFunc Thanks in advance. Link to comment Share on other sites More sharing options...
TheXman Posted December 9, 2019 Share Posted December 9, 2019 (edited) 30 minutes ago, jcpetu said: Local $EPOCH = 13215743943956926 / 1000000; 16/10/2019 08:59:03 p.m. That GMT epoch value for "2019-10-06 8:59:03 p.m." is 1571259543 . I have no idea where you got your value. Edited December 9, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
mikell Posted December 9, 2019 Share Posted December 9, 2019 $time = 1571259543 $aCall = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $time) Msgbox(0,"", $aCall[0]) $time = 13215743943956926 / 10000000 $aCall = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $time) Msgbox(0,"", $aCall[0]) jcpetu 1 Link to comment Share on other sites More sharing options...
jcpetu Posted December 9, 2019 Author Share Posted December 9, 2019 2 hours ago, mikell said: $time = 1571259543 $aCall = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $time) Msgbox(0,"", $aCall[0]) $time = 13215743943956926 / 10000000 $aCall = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $time) Msgbox(0,"", $aCall[0]) Thanks a lot mikell, by the way, do you know if it is any way for the function to return the timestamp in the format dd/mm/aa hh:mm:ss? or some black magic with StringRegExp! Link to comment Share on other sites More sharing options...
jcpetu Posted December 9, 2019 Author Share Posted December 9, 2019 9 hours ago, TheXman said: That GMT epoch value for "2019-10-06 8:59:03 p.m." is 1571259543 . I have no idea where you got your value. Hi TheXman, I wasn't sure it was the timestamp, that's the reason I wanted to convert it to readable. Link to comment Share on other sites More sharing options...
Musashi Posted December 9, 2019 Share Posted December 9, 2019 59 minutes ago, jcpetu said: do you know if it is any way for the function to return the timestamp in the format dd/mm/aa hh:mm:ss? Maybe this : #include <Date.au3> Local $iTimeStamp = 1571259543 Local $sDate = _DateAdd('s', $iTimeStamp, '1970/01/01 00:00:00') Local $sDate2 = StringRegExpReplace($sDate, "(\d{4})/(\d{2})/(\d{2}) (\d{2}):(\d{2}):(\d{2})", "${3}/${2}/${1} ${4}:${5}:${6}") ConsoleWrite("> EpochToDate = " & $sDate & @CRLF) ConsoleWrite("> Dateformat2 = " & $sDate2 & @CRLF) jcpetu 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
jcpetu Posted December 9, 2019 Author Share Posted December 9, 2019 1 hour ago, Musashi said: Maybe this : #include <Date.au3> Local $iTimeStamp = 1571259543 Local $sDate = _DateAdd('s', $iTimeStamp, '1970/01/01 00:00:00') Local $sDate2 = StringRegExpReplace($sDate, "(\d{4})/(\d{2})/(\d{2}) (\d{2}):(\d{2}):(\d{2})", "${3}/${2}/${1} ${4}:${5}:${6}") ConsoleWrite("> EpochToDate = " & $sDate & @CRLF) ConsoleWrite("> Dateformat2 = " & $sDate2 & @CRLF) Hi Musashi, yes it does it! Thanks a lot. Link to comment Share on other sites More sharing options...
jchd Posted December 9, 2019 Share Posted December 9, 2019 For the record, SQLite doesn't propose any timestamp specific format. You can store dates as text (e.g. '2019-12-09 17:32:17'), as integer (e.g. Un*x epoch), as Julian date, as Julian day, whatever. You have to be consistent: reading back timestamps under the format you used when storing them. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jcpetu Posted December 10, 2019 Author Share Posted December 10, 2019 Hi people, Im sorry to bother but the example works well for 10 digits timestamp but Chrome's timestamp is formatted as the number of microseconds since January, 1601 so I need to convert to seconds, calculate seconds until 01/01/1601 and finally add the decimal part of EPOCH. I do all calculations but the timestamp doesn't match with original timestamp, so if anyone could help please I will appreciate. #include <array.au3> #include <Constants.au3> #include <Date.au3> ; 13218946054701800 = 22/11/2019 22:27:34 $EPOCHtime = 13218946054701800 / 1000000 ;------------------ convert from microseconds to seconds --------------------- ConsoleWrite("$EPOCHtime = "&$EPOCHtime &@CRLF) $time1 = _DateAdd('s', Int($EPOCHtime), "1601/01/01 00:00:00"); Chrome time base, 1601 ConsoleWrite("$time1 = " & $time1 & @CRLF) $decimalPart=$EPOCHtime -Int($EPOCHtime) ConsoleWrite("$decimalPart= "&$decimalPart&@CRLF) $time2 = _DateAdd('s',Int($decimalPart), $time1 ) ConsoleWrite("$time2 = " & $time2 & @CRLF) --> output $EPOCHtime = 13218946054.7018 $time1 = 2019/11/23 01:27:34 $decimalPart= 0.701799392700195 $time2 = 2019/11/23 01:27:34 Link to comment Share on other sites More sharing options...
Zedna Posted December 10, 2019 Share Posted December 10, 2019 Look at sources of _DateAdd() in Date.au3 include and add ConsoleWrite also there to see what's exactly happening ... Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
KaFu Posted December 10, 2019 Share Posted December 10, 2019 (edited) Chrome time is based on UTC, add / subtract the offset to your own timezone. Edit - This works fine for me: #include <array.au3> #include <Constants.au3> #include <Date.au3> ; 13218946054701800 = 22/11/2019 22:27:34 $EPOCHtime = 13220446295000000 / 1000000 ;------------------ convert from microseconds to seconds --------------------- $a_TimeZoneInfo = _Date_Time_GetTimeZoneInformation() $EPOCHtime -= $a_TimeZoneInfo[1]*60 ConsoleWrite("$EPOCHtime = "&$EPOCHtime &@CRLF) $time1 = _DateAdd('s', Int($EPOCHtime), "1601/01/01 00:00:00"); Chrome time base, 1601 ConsoleWrite("$time1 = " & $time1 & @CRLF) $decimalPart=$EPOCHtime -Int($EPOCHtime) ConsoleWrite("$decimalPart= "&$decimalPart&@CRLF) $time2 = _DateAdd('s',Int($decimalPart), $time1 ) ConsoleWrite("$time2 = " & $time2 & @CRLF) Edited December 10, 2019 by KaFu jcpetu 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
jcpetu Posted December 10, 2019 Author Share Posted December 10, 2019 KaFu, yes it works now, thanks a lot. Link to comment Share on other sites More sharing options...
jchd Posted December 10, 2019 Share Posted December 10, 2019 (edited) Since the topic was also on SQLite, you can use SQLite to perform the conversion for you, without using application code: select datetime(13218946054701800 / 1000000 + strftime('%s', '1601-01-01'), 'unixepoch', 'localtime') as Converted; outputs: 2019-11-23 02:27:34 We clearly don't have the same localtime than OP (here = Paris). Better yet, use an SQLite trigger to perform once for all the conversion when the Chrome epoch data is entered. E.g. CREATE TABLE [T]( [Date] CHAR; CREATE TRIGGER [trInsChromeEpoch] AFTER INSERT ON [T] FOR EACH ROW WHEN CAST([new].[Date] AS INT) > 9999 BEGIN UPDATE [T] SET [Date] = DATETIME ([new].[Date] / 1000000 + STRFTIME ('%s', '1601-01-01'), 'unixepoch', 'localtime') WHERE [rowid] = [new].[rowid]; END; INSERT INTO [T] VALUES(13218946054701800); Edited December 10, 2019 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jcpetu Posted December 10, 2019 Author Share Posted December 10, 2019 jchd, yes this is an interesting option. And if want to read a filled field with the EPOCH number 13 218946054701800, how do you do to convert? Link to comment Share on other sites More sharing options...
jchd Posted December 10, 2019 Share Posted December 10, 2019 A trigger like the one examplified above would do. If you already have a table populated with Chrome epoch column(s), you just have to perform a massive UPDATE. Use a 3rd-party SQLite manager (I warmly recommend SQLite Expert), run the above SQL snippet and watch the result being what you expect. Due to our distinct timezones, you won't have the same output as Kafu or myself, but it should make you happy. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jcpetu Posted December 10, 2019 Author Share Posted December 10, 2019 OK, I'll test it. Thanks a lot jchd. Link to comment Share on other sites More sharing options...
jcpetu Posted July 28, 2020 Author Share Posted July 28, 2020 Hi, now trying to convert a timestamp to Chrome/webkit I can' t achieve it. So if somebody can help I'll appreciate. #include <Date.au3> Local $Date = "2020/07/27 16:22:23" ;=13240351343870418 ConsoleWrite("Timestamp to Chrome/webkit = " & HumanToWebkit($Date) & @CRLF) ;OK Func HumanToWebkit($Date) Local $WebKit = _DateAdd('s', -Int($Date), "1601/01/01 00:00:00") Local $a_TimeZoneInfo = _Date_Time_GetTimeZoneInformation() $Seconds = $a_TimeZoneInfo[1] * 60 Local $DateWebKit = ($WebKit * ($Seconds + ($WebKit * 1000000))) Return StringFormat("%017i", $DateWebKit) EndFunc ;==>HumanToWebkit Link to comment Share on other sites More sharing options...
Nine Posted July 28, 2020 Share Posted July 28, 2020 Maybe this : Local $Date = "2020/07/27 16:22:23" ;=13240351343870418 ConsoleWrite("Timestamp to Chrome/webkit = " & HumanToWebkit($Date) & @CRLF) ;OK Func HumanToWebkit($Date) Local $WebKit = _DateDiff('s', "1601/01/01 00:00:00", $Date) Local $a_TimeZoneInfo = _Date_Time_GetTimeZoneInformation() $Seconds = $a_TimeZoneInfo[1] * 60 Local $DateWebKit = $WebKit + $Seconds Return Int($DateWebKit & "000000") EndFunc ;==>HumanToWebkit jcpetu 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jcpetu Posted July 28, 2020 Author Share Posted July 28, 2020 Nine, yes this is OK. Thanks a lot. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now