Visit Our UNIX and Linux User Community


Date conversion


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Date conversion
# 1  
Old 08-04-2009
Date conversion

Hi all,

When using ls -l I get the details of a filename with the date in the format
Jun 22, is

I need to get it as 22/06, is there any ls command that would do this or is there a way to do this ?
# 2  
Old 08-04-2009
Depends on what kind of system you have. In most linux systems you will have the GNU version of ls, which supports --time-style:
Code:
$ man ls

LS(1)                            User Commands                           LS(1)



NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

...

       --time-style=STYLE
              with  -l, show times using style STYLE: full-iso, long-iso, iso,
              locale, +FORMAT.  FORMAT is interpreted like `date';  if  FORMAT
              is  FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files
              and FORMAT2 to recent files; if STYLE is prefixed with `posix-',
              STYLE takes effect only outside the POSIX locale

# 3  
Old 08-04-2009
HI CORONA,

I tried using -iso and getting this,

$ ls -iso FNDOPP*
1041501 16 -rw-r--r-- 1 fgdffdd 14471 Jul 17 03:12 P520738.txt

still I am getting Jul 17.
Could you give an example ?
# 4  
Old 08-04-2009
There is no -iso. You forgot the --time-style= part. ls -l --time-style=iso
# 5  
Old 08-04-2009
It worked.
Many thnx.

Also I have the timestamp written in a reporting file as 17-JUL-2009 03:45:59.
Hw to convert it to 17-07-2009 03:45:59, so that I can compare the ls file time stamp with this.

Last edited by happyrain; 08-04-2009 at 05:05 PM..
# 6  
Old 08-04-2009
Code:
$ man ls

LS(1)                            User Commands                           LS(1)



NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

...

       --time-style=STYLE
              with  -l, show times using style STYLE: full-iso, long-iso, iso,
              locale, [color=red]+FORMAT.  FORMAT is interpreted like `date'[/color=red];  if  FORMAT
              is  FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files
              and FORMAT2 to recent files; if STYLE is prefixed with `posix-',
              STYLE takes effect only outside the POSIX locale

$ man date
DATE(1)                          User Commands                         DATE(1)



NAME
       date - print or set the system date and time

SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

...

       %%     a literal %

       %a     locale's abbreviated weekday name (e.g., Sun)

       %A     locale's full weekday name (e.g., Sunday)

       %b     locale's abbreviated month name (e.g., Jan)

       %B     locale's full month name (e.g., January)

       %c     locale's date and time (e.g., Thu Mar  3 23:05:25 2005)

       %C     century; like %Y, except omit last two digits (e.g., 21)

       %d     day of month (e.g, 01)

       %D     date; same as %m/%d/%y

       %e     day of month, space padded; same as %_d

       %F     full date; same as %Y-%m-%d

       %g     last two digits of year of ISO week number (see %G)

       %G     year of ISO week number (see %V); normally useful only with %V

       %h     same as %b

       %H     hour (00..23)

       %I     hour (01..12)

       %j     day of year (001..366)

       %k     hour ( 0..23)

       %l     hour ( 1..12)

       %m     month (01..12)

       %M     minute (00..59)

       %n     a newline

       %N     nanoseconds (000000000..999999999)

       %p     locale's equivalent of either AM or PM; blank if not known

       %P     like %p, but lower case

       %r     locale's 12-hour clock time (e.g., 11:11:04 PM)

       %R     24-hour hour and minute; same as %H:%M

       %s     seconds since 1970-01-01 00:00:00 UTC

       %S     second (00..60)

       %t     a tab

       %T     time; same as %H:%M:%S

       %u     day of week (1..7); 1 is Monday

       %U     week number of year, with Sunday as first day of week (00..53)

       %V     ISO week number, with Monday as first day of week (01..53)

       %w     day of week (0..6); 0 is Sunday

       %W     week number of year, with Monday as first day of week (00..53)

       %x     locale's date representation (e.g., 12/31/99)

       %X     locale's time representation (e.g., 23:13:48)

       %y     last two digits of year (00..99)

       %Y     year

       %z     +hhmm numeric timezone (e.g., -0400)

       %:z    +hh:mm numeric timezone (e.g., -04:00)

       %::z   +hh:mm:ss numeric time zone (e.g., -04:00:00)

       %:::z  numeric time zone with :  to  necessary  precision  (e.g.,  -04,
              +05:30)

       %Z     alphabetic time zone abbreviation (e.g., EDT)

$ ls -l --time-style=+'%d-%m-%Y %T'

-rw-r--r--  1 tyler users   5630425 14-05-2004  0:27:34 4059.pdf
...

# 7  
Old 08-04-2009
what r the fields in ls -al listing?
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #266
Difficulty: Easy
In 1952, Alan Turing was prosecuted for homosexual acts a criminal offense in the UK and accepted chemical castration treatment as an alternative to prison.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Date conversion

Hi , we have a string with yyyymmdd format . how to know which date it is ? example:20120712-->sunday 20150228-->saturday 20140431-->invalid please suggest commands which work on below os : SunOS 5.10 shell: bash shell Thanks, Srinath. (10 Replies)
Discussion started by: srinadhreddy27
10 Replies

2. Shell Programming and Scripting

Date conversion

Trying to convert dates using a Perl Script but it has to accept formats like 3 letter month, day and year like Nov 02 2010 or 1/4/11 or 21 Feb 2011 and have it convert to something like October 20, 2011. Any ideas? (2 Replies)
Discussion started by: reduxeffect81
2 Replies

3. Shell Programming and Scripting

Julian date to Calendar date conversion

Hi all, I require to convert julian date to normal calander date in unix for eg julian date=122 now i want corresponding calander date ---------------------------------------- gr8 if give very small command/script and please explain the steps as well(imp) Thanks ... (3 Replies)
Discussion started by: RahulJoshi
3 Replies

4. UNIX for Dummies Questions & Answers

Date conversion in ab i

(string(8)) ((date("YYYYMMDD")) ((date("YYYY/MM/DD")) in.date_field_name)) (1 Reply)
Discussion started by: dr46014
1 Replies

5. Shell Programming and Scripting

Conversion of date to Julian date

Hi Gurus, Need help in Conversion of date(2007-11-30) to Julian date(YYDDD)... '+%J' 2007-11-30 to 'YYDDD' Thanks (4 Replies)
Discussion started by: SeenuGuddu
4 Replies

6. Shell Programming and Scripting

Date conversion

Hi, I have the string YYYYMMDDHHMMSS like 20090801204150 and I need to convert it using the unix command date in the format: date "Saturday, 1 August 2009 20:40:59" All in one single Unix line if this is possible. What's the correct syntax? Steve Hagi (6 Replies)
Discussion started by: hagimeno
6 Replies

7. Shell Programming and Scripting

Date conversion

Hi I want to convert MAY 05 2005 01:15:00PM date format to 2005/05/05 01:15:00PM . CAn somebody suggest me a code ,I am new to unix shell programming. Thanks Arif (21 Replies)
Discussion started by: mab_arif16
21 Replies

8. Shell Programming and Scripting

Date Conversion

Hi, Does anyone know (in KSH, CSH, SED or AWK), how to convert date text in a file from: EX: May232008 to: 05232008 Thanks, (3 Replies)
Discussion started by: jgrant746
3 Replies

9. Shell Programming and Scripting

date conversion

file1 E106,0,1/9/1993,0,E001,E003,A,45200,3766.667,21.730769 E108,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538 E109,0,06-mar-07,0,E001,E001,A,78000,6500,37.5 E110,0,09-dec-2008,0,E001,E001,A,56000,4666.667,26.923077 E104,0,06/04/1994,0,E001,E003,A,95000,7916.667,45.673077... (14 Replies)
Discussion started by: charandevu
14 Replies

10. Shell Programming and Scripting

date conversion

Hi everybody: Could anybody tell me how I convert from a julian date, with shell comands, to gregorian. Thanks in advance. (2 Replies)
Discussion started by: tonet
2 Replies

Featured Tech Videos