Bash - convert string to date -


i need convert date in bash string has hour included, such as: 2012-02-09-18, , store result inside variable, can compare such strings dates. if use conversion

  date -d "2012-02-09-18" 

it crash "invalid date error". how can this?

you can tweak input make parseable date using sed:

str='2012-02-09-18'  date -d "$(sed 's/-\([^-]*\)$/ \1/' <<< "$str")" thu feb  9 18:00:00 est 2012 

Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -