1

In GNU with the command date I can do it:

date -d "+4 day"


datei=20130101
i=5
date -d "$datei +$i day"

But i like know:

how can i do it in Solaris?

with the date command

Code Geas Coder
  • 1,839
  • 4
  • 23
  • 29
  • Depending on the Solaris version and what packages the local admin has installed, GNU date may be available in `/usr/gnu/bin/date`, or as `gdate` in a directory such as `/usr/sfw/bin`, `/opt/csw/bin/`, `/usr/local/bin/`, etc. – alanc Jul 24 '13 at 07:19

1 Answers1

4

Tcl has a good free-form date scanner, if you have Tcl installed (try which tclsh). A shell function:

tcldate() {
    d=${1:-now}   # the date string
    f=${2:-%c}    # the output format
    echo "puts [clock format [clock scan {$d}] -format {$f}]" | tclsh
}

In action on an ancient Solaris 8 box with bash 2.03 and tcl 8.3.3

$ tcldate
Tue Jul 23 13:27:17 2013
$ i=4
$ tcldate "$i days"
Sat Jul 27 13:27:34 2013
$ tcldate "$i days" "%Y-%m-%d"
2013-07-27
$ tcldate "20130101 + $i days" "%Y-%m-%d"
2013-01-05

This even handles daylight savings transitions:

$ tcldate "2014-03-09 00:30 + 1 hour" "%D %T %Z"
03/09/14 01:30:00 EST
$ tcldate "2014-03-09 00:30 + 2 hour" "%D %T %Z"
03/09/14 03:30:00 EDT
$ tcldate "2013-11-03 00:30 + 1 hour" "%D %T %Z"
11/03/13 01:30:00 EDT
$ tcldate "2013-11-03 00:30 + 2 hour" "%D %T %Z"
11/03/13 01:30:00 EST
glenn jackman
  • 238,783
  • 38
  • 220
  • 352