User Tools

Site Tools


date
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


date [2013/01/28 04:29] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== date ======
 +
 +Usage: date [OPTION]... [+FORMAT]<br /> or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY|.ss]]<br />Display the current time in the given FORMAT, or set the system date.<br /><br /> -d, --date''STRING        display time described by STRING, not `now'<br /> -f, --file''DATEFILE      like --date once for each line of DATEFILE<br /> -r, --reference''FILE     display the last modification time of FILE<br /> -R, --rfc-2822           output date and time in RFC 2822 format.<br />                           Example: Mon, 07 Aug 2006 12:34:56 -0600<br />     --rfc-3339''TIMESPEC  output date and time in RFC 3339 format.<br />                           TIMESPEC''`date', `seconds', or `ns' for<br />                           date and time to the indicated precision.<br />                           Date and time components are separated by<br />                           a single space: 2006-08-07 12:34:56-06:00<br /> -s, --set''STRING         set time described by STRING<br /> -u, --utc, --universal   print or set Coordinated Universal Time<br />     --help    display this help and exit<br />     --version output version information and exit<br /><br />FORMAT controls the output. The only valid option for the second form<br />specifies Coordinated Universal Time. Interpreted sequences are:<br /><br /> %%  a literal %<br /> %a  locale's abbreviated weekday name (e.g., Sun)<br /> %A  locale's full weekday name (e.g., Sunday)<br /> %b  locale's abbreviated month name (e.g., Jan)<br /> %B  locale's full month name (e.g., January)<br /> %c  locale's date and time (e.g., Thu Mar 3 23:05:25 2005)<br /> %C  century; like %Y, except omit last two digits (e.g., 21)<br /> %d  day of month (e.g, 01)<br /> %D  date; same as %m/%d/%y<br /> %e  day of month, space padded; same as %_d<br /> %F  full date; same as %Y-%m-%d<br /> %g  last two digits of year of ISO week number (see %G)<br /> %G  year of ISO week number (see %V); normally useful only with %V<br /> %h  same as %b<br /> %H  hour (00..23)<br /> %I  hour (01..12)<br /> %j  day of year (001..366)<br /> %k  hour ( 0..23)<br /> %l  hour ( 1..12)<br /> %m  month (01..12)<br /> %M  minute (00..59)<br /> %n  a newline<br /> %N  nanoseconds (000000000..999999999)<br /> %p  locale's equivalent of either AM or PM; blank if not known<br /> %P  like %p, but lower case<br /> %r  locale's 12-hour clock time (e.g., 11:11:04 PM)<br /> %R  24-hour hour and minute; same as %H:%M<br /> %s  seconds since 1970-01-01 00:00:00 UTC<br /> %S  second (00..60)<br /> %t  a tab<br /> %T  time; same as %H:%M:%S<br /> %u  day of week (1..7); 1 is Monday<br /> %U  week number of year, with Sunday as first day of week (00..53)<br /> %V  ISO week number, with Monday as first day of week (01..53)<br /> %w  day of week (0..6); 0 is Sunday<br /> %W  week number of year, with Monday as first day of week (00..53)<br /> %x  locale's date representation (e.g., 12/31/99)<br /> %X  locale's time representation (e.g., 23:13:48)<br /> %y  last two digits of year (00..99)<br /> %Y  year<br /> %z  +hhmm numeric timezone (e.g., -0400)<br /> %:z +hh:mm numeric timezone (e.g., -04:00)<br /> %::z +hh:mm:ss numeric time zone (e.g., -04:00:00)<br /> %:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)<br /> %Z  alphabetic time zone abbreviation (e.g., EDT)<br /><br />By default, date pads numeric fields with zeroes.<br />The following optional flags may follow `%':<br /><br /> - (hyphen) do not pad the field<br /> //(underscore) pad with spaces<br /> 0 (zero) pad with zeros<br /> ^ use upper case if possible<br /> # use opposite case if possible<br /><br />After any flags comes an optional field width, as a decimal number;<br />then an optional modifier, which is either<br />E to use the locale's alternate representations if available, or<br />O to use the locale's alternate numeric symbols if available.<br /><br />Report bugs to &lt;bug-coreutils@gnu.org&gt;.
 +
 +===== How To Get Yesterday's Date using BASH Shell =====
 +
 +The new short way:
 +<file>
 +$ date -d '1 day ago' +'%Y/%m/%d'
 +2012/05/18
 +</file>
 +
 +Or the longer way: Yesterday in epoch seconds
 +<file>
 +$ yesterday''$((`date +'%s'` - 86400))
 +</file>
 +
 +Get default formatted yesterday's date
 +<file>
 +$ date -d "1970-01-01 $yesterday sec"
 +Thu May 18 01:27:32 MST 2012
 +</file>
 +
 +Same thing in YY-MM-DD
 +<file>
 +$ date -d "1970-01-01 $yesterday sec" +"%Y-%m-%d"
 +2012-05-18
 +</file>
 +
 +-- Main.FredPettis - 2012-05-19
  
date.txt · Last modified: 2013/01/28 04:29 by 127.0.0.1