Linux Tip : Split Date into Day, Month, Year

Like Tweet Pin it Share Share Email

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


Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *