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 can I get an ISO-8601 date in Bash?

Well I can get a current ISO-8601 time with date +"%Y-%m-%1dT%H:%M:%S%z" command in Bash.
The output was 2022-09-19T00:33:55+0900!
However, I want to get the yesterday since that command output.
I mean I want to get the output like 2022-09-18T00:33:55+0900
Can anyone help me?

>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

Use the --date option, like this:

date --date="yesterday" +"%Y-%m-%1dT%H:%M:%S%z"

Note that instead of writing out that whole format string, you can use -Iseconds, like this:

date --date="yesterday" -Iseconds
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