Giving two variables with the followind values:
date1 = Mon Feb 27 16:21:34 WET 2012
date2 = Mon Feb 27 16:29:34 WET 2012
How can I make the difference (in minutes) between them using ksh?
I'm using Solaris 10.
I made what you said and this was the error:
$ function d { echo $((($(date -d"$2" +%s)-$(date -d"$1" +%s))/60)); }
$ d "Mon Feb 27 16:21:34 WET 2012" "Mon Feb 27 16:29:34 WET 2012"
date: illegal option -- d
date: illegal option -- M
date: illegal option -- o
date: illegal option -- n
date: illegal option --
date: illegal option -- F
date: illegal option -- e
date: illegal option -- b
date: illegal option --
date: illegal option -- 2
date: illegal option -- 7
date: illegal option --
date: illegal option -- 1
date: illegal option -- 6
date: illegal option -- :
date: illegal option -- 2
date: illegal option -- 9
date: illegal option -- :
date: illegal option -- 3
date: illegal option -- 4
date: illegal option --
date: illegal option -- W
date: illegal option -- E
date: illegal option -- T
date: illegal option --
date: illegal option -- 2
date: illegal option -- 0
date: illegal option -- 1
date: illegal option -- 2
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
date: illegal option -- d
date: illegal option -- M
date: illegal option -- o
date: illegal option -- n
date: illegal option --
date: illegal option -- F
date: illegal option -- e
date: illegal option -- b
date: illegal option --
date: illegal option -- 2
date: illegal option -- 7
date: illegal option --
date: illegal option -- 1
date: illegal option -- 6
date: illegal option -- :
date: illegal option -- 2
date: illegal option -- 1
date: illegal option -- :
date: illegal option -- 3
date: illegal option -- 4
date: illegal option --
date: illegal option -- W
date: illegal option -- E
date: illegal option -- T
date: illegal option --
date: illegal option -- 2
date: illegal option -- 0
date: illegal option -- 1
date: illegal option -- 2
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
0
$
using a
date
which supports-d
,You don't have GNU date. You might have Tcl installed:
well, here's a C program that might work. it's (lightly) tested on solaris.
it uses the POSIX standard strptime(3) function to parse a given string and prints the result in epoch seconds.
in theory invocation should be
but i haven't been able to get it to recognize the "WET" timezone, so you may need to just put that in as a literal:
here's the code:
compile with something along the lines of
(probably requires gcc, no idea if sun cc will work here)