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.

$dat=’13/2/2015′

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

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

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