Go to:  Davar site entry | Site contents | Site index | Client/Server | References | Text bottom

Date  and  Time  Formatting  Characters

Date and time formatting characters are listed with explanation of their meaning in manual pages of ckdate and cktime commands.  However, those man pages are for whatever reasons incomplete and some useful formats are omitted.

Korns script dt listed below displays all more a less meaningful date command formatting characters (those formats that produce result different from themselves, i.e. formats that get interpreted).  Script is relatively small and is presented as a function that could be defined in .profile file, which is normally executed automatically at user login.



# -------- Display Date and Time Formatting Characters -------------------------

  function dt { echo Date and Time Formatting Characters
                date
                A="   a b c d e f g h i j k l m n o p q r s t u v w x y z"
                A="$A A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
                for C in $A
                    do D=$(date +%$C)
                       if [[ "$D" != %$C ]]
                          then echo date +%$C -- $D
                       fi
                    done
                unset A C D; }
  


Below is the result of dt script execution with common sense explanations of formats' meaning.
(Some comments are not obvious directly from the example; they were obtained as a result of
experimenting at different dates an times, as well as from ckdate and cktime manual pages.)



   # dt
   Date and Time Formatting Characters
   Fri Oct 12 21:48:11 EDT 2001
   date +%a -- Fri   .  .  .  .  .  .  .  .
   date +%b -- Oct   .  .  .  .  .  .  .  .
   date +%c -- Fri Oct 12 21:48:12 2001
   date +%d -- 12    .  .  .  .  .  .  .  .
   date +%e -- 12    .  .  .  .  .  .  .  .
   date +%h -- Oct   .  .  .  .  .  .  .  .
   date +%j -- 285   .  .  .  .  .  .  .  .
   date +%k -- 21    .  .  .  .  .  .  .  .
   date +%l --  9    .  .  .  .  .  .  .  .
   date +%m -- 10    .  .  .  .  .  .  .  .
   date +%n --
   date +%p -- PM    .  .  .  .  .  .  .  .
   date +%r -- 04:48:12 PM    .  .  .  .  .
   date +%t --
   date +%u -- 6  .  .  .  .  .  .  .  .  .
   date +%w -- 5  .  .  .  .  .  .  .  .  .
   date +%x -- 10/12/01    .  .  .  .  .  .
   date +%y -- 01    .  .  .  .  .  .  .  .
   date +%A -- Friday   .  .  .  .  .  .  .
   date +%B -- October  .  .  .  .  .  .  .
   date +%C -- Fri Oct 12 21:48:13 EDT 2001
   date +%D -- 10/12/01    .  .  .  .  .  .
   date +%E -- %_=/usr/bin/date
   date +%H -- 21    .  .  .  .  .  .  .  .
   date +%I -- 09    .  .  .  .  .  .  .  .
   date +%M -- 48    .  .  .  .  .  .  .  .
   date +%O -- %_=/usr/bin/date
   date +%R -- 21:48    .  .  .  .  .  .  .
   date +%S -- 14    .  .  .  .  .  .  .  .
   date +%T -- 21:48:14    .  .  .  .  .  .
   date +%U -- 40    .  .  .  .  .  .  .  .
   date +%V -- 41    .  .  .  .  .  .  .  .
   date +%W -- 41    .  .  .  .  .  .  .  .
   date +%X -- 21:48:14    .  .  .  .  .  .
   date +%Y -- 2001  .  .  .  .  .  .  .  .
   date +%Z -- EDT   .  .  .  .  .  .  .  .
          




  Default date format
  Day of a week abbreviated name
  Month of a year abbreviated name
  Full current date (without time zone)
  Day number within current month (0131)
  Day number within current month ( 131)
  Month of a year abbreviated name
  Day number within the current year
  Hour military (24 hour scale)
  Hour AM/PM ( 112)
  Month number within the current year

  Ante Meridian / Post Meridian indicator
  Current time HH:MM:SS AM/PM

  Day of a week number (starting Sunday=1)
  Day of a week number (starting Monday=1)
  Current date MM/DD/YY
  Year number within the current century
  Day of a week full name
  Month of a year full name
  Full current date with time zone
  Current date MM/DD/YY

  Hour military (24 hour scale: 0023)
  Hour AM/PM (0112)
  Minute within the current hour (0059)

  Current time HH:MM military (24 hour)
  Second within current minute (0059)
  Current time HH:MM:SS military (24 hour)
  Number of full weeks since year beginning
  Week number within the current year
  Week number within the current year
  Current time HH:MM:SS military (24 hour)
  Full current year CCYY (century and year)
  Current time zone acronym
	  



Formats displayed by dt script can be combined with themselves and with other symbols.



   # date +%Y%m%d    .  .  .  .  .  .  .  .
   20011029

   # date +%Y-%m-%d     .  .  .  .  .  .  .
   20011029

   # date +%D  %R    .  .  .  .  .  .  .  .
   10/29/01

   # date '+%D  %R'     .  .  .  .  .  .  .
   10/29/01  13:36

   # date '+%A, %B %d %Y  %I:%M %p'    .  .
   Monday, October 29 2001  01:44 PM
          

  Use combination of format elements


  Use symbols to delimit format elements


  Second part of format is ignored
  (due to interfering spaces)

  Use single quotes to insert spaces


  Combine any format elements with symbols
	  


Go to:  Davar site entry | Site contents | Site index | Client/Server | References | Text top