Search code examples
unixunix-timestampdos2unix

Convert unix date to integer value


hi i have my UNIX file date in particular format 2017-02-01 i want to convert it in integer value like 20170201. What can i do get this output.My UNIX box is(SunOS 5.10).I tried to check below command to see what they output.But i am not getting anything.Can anyone help?

bash-3.2$ date +'%s'
%s
bash-3.2$ date +"%s"
%s
bash-3.2$ date +%s
%s

When i try date -d "Filename" +%Y%m%d option it error out saying:-

date: bad conversion
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

Solution

  • You can get the date you like with this line of code (bash):

    date +"%Y%m%d"
    

    you can use it as a filename like this:

    _now=$(date +"%Y%m%d")
    _file="/tmp/$_now.ext"
    

    then use $_file for your filename