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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -