Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert time stamp into epoch time stamp

How can I convert the following into epoch using date?:

oldDate="Dec 23 17:24:13 2022"
date -d $oldDate +%s

date: extra operand ‘17:24:13’

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to wrap your variable in quotes, like so:

oldDate="Dec 23 17:24:13 2022"
date -d "$oldDate" +%s

Otherwise bash sees the spaces inside the variable and tries to split it into multiple arguments.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading