Can somebody please tell me how to do string value conversion to epoch time in ksh shell (HP-UX). My string value is of format "20170610 08:18:30
". I was able to do this in bash using date -d"$stringdate $stringtime" +%s
. Also date +%s
doesn't work in ksh, I have used perl -e "print time"
to get epoch time but I am unable to convert my string to epoch value.
Asked
Active
Viewed 1,032 times
0

ArturFH
- 1,697
- 15
- 28

Deepak Mohan
- 1
- 2
-
Please run `type date` either in bash as in ksh and check, if results are the same. What happens when you run `date +%s` in ksh? – ArturFH Jun 10 '17 at 16:47
-
Running this command in Ksh gives error. It says " bad format character - s". I think date command option '+%s' is not supported in Ksh. Perl or mathematical formula should be used instead. – Deepak Mohan Jun 10 '17 at 17:06
-
What about `type date` results? Did you check that? – ArturFH Jun 10 '17 at 17:50
-
type date in bash gives output :- date is a tracked alias for /bin/date. Same command in ksh shell gives output :- date is a tracked alias for /usr/bin/date. Also, I am using different server for bash and ksh. – Deepak Mohan Jun 10 '17 at 18:24
-
type date in bash gives:- date is tracked alias for /bin/date and same command in ksh gives output:- date is a tracked alias for /usr/bin/date – Deepak Mohan Jun 10 '17 at 18:28
-
1So, it has nothing to do with the shell, but with the date implementation on those machines. – ArturFH Jun 10 '17 at 18:58
-
Thanks for the information Artur. But then how do I make the conversion on that machine? I searched everywhere but couldn't find any. I need to get epoch value from the string. Is their any other way to do this conversion. – Deepak Mohan Jun 10 '17 at 19:34
-
Check the BSD section from [this answer](https://stackoverflow.com/a/14805690/2989411). If it won't help, google for: "how to convert data string to epoch in
". – ArturFH Jun 10 '17 at 19:37 -
what version of ksh are you using? – pynexj Jun 12 '17 at 09:47
-
I am using HP-UX B.11.11 U 9000/800 – Deepak Mohan Jun 12 '17 at 18:47