0

I am generating string using date +"%Y%m%d%H" and reading the same string to convert back as date. somehow reverse is not working. and %Y is treated as first six characters

# date +"%Y%m%d%H"
2017030216

# date -d 2017030215 +%Y
201703

# date -d 2017030215 +%m
02

Why doesn't this return 2017?

1 Answer 1

2

You are passing invalid strings to -d, i.e. strings which are not in accordance with its expected format. The documentation of that format is here: https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html

"2017030215" is not a valid date/time string in most systems, and date -d is no exception. If you want to see how date -d is interpreting your string, just run it without the + option to see the full output. You'll probably be surprised.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.