- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Input variable having YYYMMDD:HHMMSS format to con...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 03:40 AM
01-28-2022 03:40 AM
Hi,
I search everywhere, man pages, google without no success. I need to convert to Epoch Milliseconds an input string stored in a korn shell variable. The format is something like YYYYMMDD:HHMMSS.
A="20220124180000"
....
Z=????
echo "$Z"
should return 1643047200
I tried with the date native function and some intricated syntax but I'm not able to say my date as input is using that format ...
Any ideas are very welcome.
Thanks in advance,
Kind regards,
Den.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 06:50 AM
01-28-2022 06:50 AM
Re: Input variable having YYYMMDD:HHMMSS format to convert to Epoch timestamp
> I tried with the date native function and some intricated syntax but
> I'm not able to say my date as input is using that format ...
With my weak psychic powers, I can't see what you tried.
> should return 1643047200
In which timezone?
I don't have an HP-UX system up at the moment, but, on a handy Mac:
"-f input_fmt new_date" seems to do what "man date" says that it
will.
$ date -j -f '%Y%m%d%H%M%S' '20220124180000'
Mon Jan 24 18:00:00 CST 2022
"'+%s" as the "[+output_fmt]" option seems to do what "man strftime"
says that it will.
$ date -j -f '%Y%m%d%H%M%S' '20220124180000' '+%s'
1643068800
UTC:
$ date -j -u -f '%Y%m%d%H%M%S' '20220124180000'
Mon Jan 24 18:00:00 UTC 2022
$ date -j -u -f '%Y%m%d%H%M%S' '20220124180000' '+%s'
1643047200
$ TZ=UTC date -j -f '%Y%m%d%H%M%S' '20220124180000'
Mon Jan 24 18:00:00 UTC 2022
$ TZ=UTC date -j -f '%Y%m%d%H%M%S' '20220124180000' '+%s'
1643047200
As usual, many things are possible.
> [...] Milliseconds [...]
"Milli"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 09:59 AM
01-28-2022 09:59 AM
Re: Input variable having YYYMMDD:HHMMSS format to convert to Epoch timestamp
Hi Steven,
Thank you but I really need this for HP because options ....
Your command did not work on HP-UX.
Kind regards,
Denis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 11:27 AM
01-28-2022 11:27 AM
Re: Input variable having YYYMMDD:HHMMSS format to convert to Epoch timestamp
> Your command did not work on HP-UX.
"did not work" is not a useful problem description. It does not
say what you did. It does not say what happened when you did it. As
usual, showing actual actions (commands) with their actual results
(error messages, ...) can be more helpful than vague descriptions or
interpretations. Copy+paste is your friend.
_Which_ HP-UX?
uname -a
> [...] I'm not able to say my date as input [...]
"I'm not able" is about as good as "did not work". "There is no
'date' option to allow me" might be a better description of the problem.
If your HP-supplied "date" program doesn't let you specify an input
date+time, then you might need to find/provide a program which does.
For example, GNU "date" (part of GNU Coreutils) seems to have a
-d/--date option. You might need to translate your date+time
specification a little to get GNU "date" to parse it.
http://hpux.connect.org.uk/hppd/hpux/Gnu/coreutils-8.27/
Or find some other, better "date" program. Or write your own program
to do the job?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2022 07:07 AM - edited 01-31-2022 01:38 AM
01-30-2022 07:07 AM - edited 01-31-2022 01:38 AM
SolutionYeah, standard HP-UX date command definitely won't support those options. The coreutils GNU date should though.
For the OP, I'm not clear why you say you want the date output to be "in milliseconds" when the input granularity isn't going below seconds. If you really insist on this output, you may as well work out number of seconds from the epoch and then multiply by 1,000.
I am an HPE Employee