Date format conversion

Hi,
i have to check the file whether it is created today. here is the

ls -l

o/p

 
-rw-r----- 20000 50000 130 Dec 12 10:21 file.txt

im able to check if file is created today or not if the timestamp is in 2014-12-12 format by comparing $(date +Y-%m-%d)
but stuckup as it is of format

Dec 12

please help in this case.

Hello JSKOBS,

Since you haven't mentioned your os, could you please try following command let us know if this helps.

stat filename

EDIT: Following command may help you to get the complete time format as you require.

ls -ltr --time-style="full-iso"
OR
ls -ltr --time-style="long-iso"

Thanks,
R. Singh

1 Like

Thanks for the reply.
would like to know is there anyway in unix, Dec 11 format can be converted 2014-12-11 format ???

Hello JSKOBS,

Not sure if you have tried command which I have given in post#2, it will give following output as per your requirement.
Kindly let me know if you have tried that command and it doesn't meet your requirement.

ls -ltr --time-style="long-iso"
-rw-r--r-- 1 singh4     singh4       33 2014-12-12 03:59 test1
drwxrwxr-x 2 singh4     singh4  240 2014-12-12 03:59 test2
drwxr-xr-x 2 singh4     singh4  160 2014-12-12 03:59 test3

Thanks,
R. Singh

actually im checking the timestamp of the file in SFTP server. During sftp, im writing the o/p to a text file. from the text file, im trying to check the file timestamp.
ls -ltr --time-style="long-iso" command is not working in sftp server.

Thankyou.

Using GNU date:

$ date --date="Dec 11" +"%Y-%m-%d"
2014-12-11
1 Like

Hello JSKOBS,

Sorry for confusion, as you have mentioned as you need the time format in ls command so only I tried to give that solution, you can convert it by following command but not tested though during sftp , give a try and let us know if that helps.

date -d"Dec 11" +"%Y-%m-%d"
OR
date -d"Dec 11" +"%Y/%m/%d"

Thanks,
R. Singh

1 Like