Linux Tip : Split Date into Day, Month, Year

Easy way to split date into  Day, Month, Year  in Linux.  This code was tested using Bash shell.


sday=$(date -d “$dat” ‘+%d’)
smonth=$(date -d “$dat” ‘+%m’)
sfourdigityear=$(date -d “$dat” ‘+%Y’)
stwodigityear=$(date -d “$dat” ‘+%y’)

echo $sday  will display   02
echo $smonth  will display   13
echo $sfourdigityear  will display   2015
echo $stwodigityear  will display   15


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: