2

In sc (spreadsheet calculator), I formatted a column with <f 12 0 3> but was unable to insert a valid date in its cells. If I digit <\^D15/12/31> (or other similar notations, with or without the initial ^D, I only get a string with no possibility to calculate date-differences. Could somebody give me any hints?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Ennio Sr
  • 21
  • 2

2 Answers2

2

You can insert a date using the @dts function, eg =@dts(15,12,31). When needed it is converted to a number of seconds since the epoch so you can calculate a difference. Eg if cell A1 has this value, and cell A2 has a day earlier =@dts(15,12,30), then you can set B1 to =A1-A2 and it will show 86400.00, i.e. the difference in seconds.

I don't think you can do anything else with this time difference except the usual arithmetic. You can use ^D (control-D) to change the display format. For example, type F^D%T whilst over the B1 cell and it will now show as hours:mins:secs 01:00:00 (see man strftime for %T), but it is still "seconds from epoch", so you cannot for example convert it into a number of weeks except by dividing by the appropriate number of seconds.

meuh
  • 49,672
  • 2
  • 52
  • 114
  • Thank you very much indeed, Meuh: you saved me a lot of time! That indication in 'man sc' about the CTRL+D at the beginning of the string to make the string identified as a date was really deceiving me. Do you have any further reading to suggest about this lovely 'vintage' spreadsheet calculator? – Ennio Sr Sep 26 '16 at 17:27
0

As an addendum to the answer, it is possible to enter both date and time, then format the entry to expectations.

Cell info, (format codes) [two formulas]:

B18 (^D%m/%d/%y %H:%M:%S) [@dts(2022,5,4)+@tts(8,30,45)]

The method:

  • Select a cell for date-time entry
  • Press e
  • @dts(2022,5,4)+@tts(8,30,45) and Enter
  • Press F
  • "^D%m/%d/%y&nbsp;&nbsp;%H:%M:%S" and Enter
  • Press f, then press l (lowercase L) repeatedly til good width, then Enter

Essential for the format string is to actually press Ctrl+D, then enter codes. See "man date" for possible codes. Formulas begin with @, where @dts(y,m,d) converts a date, and @tts(H,M,S) converts a time; both convert to seconds from epoch and can be added for a true date and time.

Also useful is man sc, and in sc press ? to see a help menu, use keys a to p anywhere in that menu or sub-menus, or q to quit back to spreadsheet.

This is a nice shell spreadsheet utility; many built-in formulas including amortizing loan and others.

Greenonline
  • 1,759
  • 7
  • 16
  • 21
orcnix
  • 1