My log-files (csv) contains timestamps in Epoch/Unix time… is it possible to convert to standard date/time?.. either at import or by calculation?
Tnx
My log-files (csv) contains timestamps in Epoch/Unix time… is it possible to convert to standard date/time?.. either at import or by calculation?
Tnx
the “date” command can do that using the “-d@” option:
date -d@1747250003
Wed May 14 03:13:23 PM EDT 2025
You can use a formatter string to change the format, for example:
date -d@1747250003 +‘%F %T’
2025-05-14 15:13:23
see the formatting codes in “man date”
Aha nice!.. and (apologies noob question) where can I add this in LabPlot?.. on the column format property?
Tnx
I didn’t know you meant doing something inline in some kind of app like have a cell calculation, the “date” command is command line. I thought you meant you had some posix times in a csv file and just wanted to obtain their real time strings as a one time thing.
I created a test csv file with some sample posix time strings and tried to import the file. I was able to import it but the “Date & Time” column format in LabPlot on that column where I had the posix times didn’t have a posix option, just ordinary formats like “HH:MM:SS” and so on.
Your best option might be to convert the posix times in the csv file before importing to a format LabPlot understands, then import it.
I wrote up a script in python that would take an input file, convert the column at “timecolnum” from posix time to ‘%Y-%m-%d %H:%M:%S’ format and then dump that to a new file of the same name with “.out” appended:
#!/bin/python3
#
#
# converttime.py [input csv filepath]
# ex: converttime.py inputdata.csv
import sys
import csv
import datetime
# change this to the column number where the posix time to convert is, range (0 to column-1)
timecolnum = 1
# the arg to the script is the input csv file, the output file is the same name with .out appended
with open(sys.argv[1], 'r') as inf, open(sys.argv[1] + ".out", 'w') as outf:
inreader = csv.reader(inf)
# write the header as is (line one in csv is usually a column identity label row)
outf.write(','.join(next(inreader)) + '\n')
for linewords in inreader:
linewords[timecolnum] = datetime.datetime.fromtimestamp(int(linewords[timecolnum]), datetime.UTC).strftime('%Y-%m-%d %H:%M:%S')
outf.write(','.join(linewords) + '\n')
Note it assumes the posix time is UTC based, that can be changed in the “fromtimestamp()”. the strftime() % string can be changed to whatever format is the target (see the codes in “man strftime” or a python wiki for it’s strftime)
Yea, see that I wasn’t too clear about using the LabPlot app other than the tag so apologies for that. And kinda assumed the workaround at this point would be to manipulate the csv ahead of import and many thanks for the quick reply… including the script!
I will mark this the solution and perhaps make a feature request for the devs to implement this option
Cheers