Script(s)

technology as-is

Linux Tip : Split Date into Day, Month, Year

| 0 comments

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

Required fields are marked *.