I am running a shell script which accepts date in "YYYY-MM-DD" format. from this date input, how can i get year, month and day separately?
Thanks for replies in advance.
except for processing the string as text(with grep/sed/awk/cut/...), you could do with with date command:
kent$ date -d '2013-09-06' +%Y
2013
kent$ date -d '2013-09-06' +%m
09
kent$ date -d '2013-09-06' +%d
06
You could do this to store them on variables with one command:
read YEAR MONTH DAY < <(date -d '2013-09-06' '+%Y %m %d')
printf "%s\n" "$YEAR" "$MONTH" "$DAY"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With