Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Is it possible to create a SilkTest function to perform a Unix timestamp conversion?

Is it possible to create a SilkTest function to perform a Unix timestamp conversion?

Yes it is, below is a function that will return the seconds since 12.00am 1/1/1970

This will facilitate that ability to verify reports that contain timestamps in that format (based on seconds since standard epoch of 1/1/1970).

NB Epoch is the amount of seconds that have passed since the 12.00am 1/1/1970

integer getUnixTimeFromDateTime(datetime dtToConvert)
 
 const datetime unixEpochDate = "1970-01-01 00:00:00"
 string sTime
 integer diffDaysInSecs
 integer daySecs
 integer unixTime
 
 diffDaysInSecs = DiffDateTime(dtToConvert, unixEpochDate) * 86400
 daySecs = (GetDateTimePart(dtToConvert, DTP_HOUR) * 3600) +
          (GetDateTimePart(dtToConvert, DTP_MINUTE) * 60) +
           GetDateTimePart(dtToConvert, DTP_SECOND)
 unixTime = diffDaysInSecs + daySecs

 return (unixTime)
 
dateTime getDateTimeFromUnixTime(integer unixTime)
 
 const datetime unixEpochDate = "1970-01-01 00:00:00"
 integer days, hours, mins, secs
 datetime dtDateTime
 
 days = unixTime / 86400
 unixTime = unixTime % 86400
 hours = unixTime / 3600
 unixTime = unixTime % 3600
 mins = unixTime / 60
 secs = unixTime % 60
 dtDateTime = AddDateTime(unixEpochDate, days, hours, mins, secs)
 
 return (dtDateTime)
 
 
main ()
 dateTime dt, dtNew
 integer unixTime
 
 dt = "2005-12-7 17:5:3"
 unixTime = getUnixTimeFromDateTime(dt)
 dtNew = getDateTimeFromUnixTime(unixTime)
 
 print ("Orig DT   = {dt}")
 print ("Unix Time = {unixTime}")
 print ("Conv DT   = {dtNew}")

Old KB# 21220

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:18
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.