I have 2 variables
startTime='122717 23:20'
endTime='122817 0:40'
how can i get the elapsed duration as like "1 hour 20 minutes" ?
I have 2 variables
startTime='122717 23:20'
endTime='122817 0:40'
how can i get the elapsed duration as like "1 hour 20 minutes" ?
What OS and shell do you work on?
OS = AIX oslevel:7.1
SHELL = KSH
Which version(s) of ksh
do you have on AIX 7.1?
What output do you get from:
ksh --version
ksh93 --version
ksh93 --version
version sh (AT&T Research) 93t+ 2009-05-01
I'm not sure if 93t+ is recent enough to support this... What output do you get from the command:
printf '%(%Y-%m-%d@%H:%M:%S %s\n)T' '12/28/17 0:40' '12/27/17 23:20'
In the US Pacific timezone, it should give you:
2017-12-28@00:40:00 1514450400
2017-12-27@23:20:00 1514445600
In other timezones, the last number on each line will be different (but the difference between those numbers will be a constant... the number of seconds between those two times).
If you do get output similar to the above, does that give you enough information to solve your problem?
This is what i get
# printf '%(%Y-%m-%d@%H:%M:%S %s\n)T' '12/28/17 0:40' '12/27/17 23:20'
(Y-%d@%M:%s
)T
#
You can always use the POSIX definition of Seconds Since the Epoch:
to calculate the number of seconds since the Epoch for both of your dates, subtract the start time from the end time and convert the resulting seconds into a number of days, hours, and minutes.
If you search these forums, you can also find methods of doing this using perl
.
I think you executed that in the standard ksh
, not in ksh93
.
Could you switch to ksh93 and try again?
$ ksh93
$ printf '%(%Y-%m-%d@%H:%M:%S %s\n)T' '12/28/17 0:40' '12/27/17 23:20'
2017-12-28@00:40:00 1514418000
2017-12-27@23:20:00 1514413200
$