Importing Linux timestamps as dates in calc

I am writing a bash script (in Linux) that writes a CSV file that starts with a timestamp followed by a number that represents an elapsed time in seconds.

I can format the file and the timestamp any way I want to.

How do I format the timestamp so that Calc recognizes it as a timestamp that can be displayed as a date and also used for date arithmetic down to seconds without creating weird formulas to parse the input field.

I will be importing the file periodically (probably into an empty sheet - or I can use some sort of a template if that helps). The point is that I want it to “just work” without a bunch of steps I have to remember and repeat.

Once that works, it would be nice - to import the file into the first few columns of a spreadsheet that already has some formulas, etc. in subsequent columns to process the data.

I know what databases are, but haven’t done anything with them in forever and would greatly prefer not having to learn base. I have used Calc for a long time and am pretty good with very simple spreadsheets.

I see a number of articles about how to live with data that already exists and isn’t understood to start with but nothing about how to get it right to start with,

I am open to using something other than CSV if it makes this task easier and isn’t too complex with a long learning curve.

You can use formulas to convert.

The only way to safely get correct and correctly interpreted data of data-time stamp type (and similar) is to use ISO 8601 from the beginning and also when exporting/importing to/from csv-style files…
Recent versions of LibO also allow to use fundamental strings based on such types as operands in calculations.
Stoneage IT made a huge mess out of all this. Do you remember the “y2k” hysteria e.g.?

My definite advice therefore:

  • For users: Omit OS dependent representations (NullDate based e.g.). Current processors can handle the needed automatic conversions fast enough. When importing from a clean csv, do not enable “Detect special numbers” then. Definitely omit any occurrence of “US dates”!
    Try the English (Canada) locale.
  • For developers: A software representing complex numbers (e.g.) as texts shouldn’t treat date-time as setting-dependent numbers. Too much of inconsistency!
    Make ISO 8601 the default for any locale (most locales?) or create at least an option for the user of any locale to to override the preset default format for the default cell-style.

About three years ago I published a set of related functions here.
Unfortunately the developing thread was messed up by badly considered posts.
A slightly updated and completed version of my local module related to the topic you find included with the attached example.

disask104184dateTimeAgain.ods (24.4 KB)

1 Like

So format the timestamp into isoformat, eg: yyyy-mm-dd HH:MM:SS

1 Like

Yeah. I just figured that out empirically. Thanks.

I’m using

    now_p="$(date '+%x %X')"

which is slightly different, but also works.

may be worth an update of Frequently asked questions - Calc - The Document Foundation Wiki :wink:

1 Like

%x shows a locale-dependent date-representation, I would recommend:

date "+%Y-%m-%s %T"
2 Likes