NAME
yest - date manipulation utility.
SYNOPSIS
yest --help yest --license
yest --version yest [--idf=str]
[[-|+]adjust[d|h|m]]
[date] [format-string]
DESCRIPTION
This is called "yest" because the default is to
output yesterday's date. This utility knows about leap year,
daylight savings time, and such variations.
This utility adds or subtracts days, hours, and/or minutes from
a given date, and outputs the results in the specified format.
The default, if no adjustment is specified, is "-1d" (subtract
one day).
Yest supports most date(1)
format codes as well as a few of its own.
OPTIONS
- --help
- Display help information.
- --license
- Display license information.
- --version
- Display version information.
--input-date-format=str
--idf=str
- Specify the default format for date input. The str
identifier may be:
|
| "ISO"
| (Format: yyyy-mm-ddThh:mi)
|
|
| "JP"
| (Format: yyyy/mm/dd-hh:mi)
|
|
| "EU"
| (Format: dd/mm/yyyy-hh:mi)
|
|
| "US"
| (Format: mm/dd/yyyy-hh:mi) |
If the format can be determined by the data, it will be. The
default format will only be used for ambiguous dates, such as
"02/03/04".
PARAMETERS
(Note that the order of the parameters is not
important.)
- adjustment
- The adjustment can be any of the following:
-
- [-|+]day-time
- Day, hour and minute adjustment specification in the format
"[-|+]day-hour:minute". For example:
"+4-12:00".
- [-|+]intd
- Explicit day adjustment amount.
- [-|+]inth
- Explicit hour adjustment amount.
- [-|+]intm
- Explicit minute adjustment amount. You can specify a
combination of day, hour and minute adjustments. For example: "yest
+3d -2h" If no adjustment is specified, the default is
"-1d".
- date
- Date to be altered. Default is today, current hour, minute and
second. date should be specified in ISO date format:
"yyyy-mm-dd"
Hours and minutes may be included:
"yyyy-mm-ddThh"
(date
+ hour)
"yyyy-mm-ddThh:mi"
(date + hour and
minute)
(Note that the
"T" before the time is a literal 'T')
Other date formats recognized are:
epoch
seconds (seconds
since 1/1/1970)
"dd/mm/yyyy"
or
"mm/dd/yyyy" (if
LANG="en_US*")
Hours and minutes may be included as follows:
"dd/mm/yyyy-hh"
(date +
hour)
"dd/mm/yyyy-hh:mi"
(date + hour and
minute)
If you specify a date but no time, the time output fields will, of
course, be zero. Currently, {date} must be between January 1, 1970
and January 18, 2038.
- format-string
- String containing date output codes and, optionally, other
text. Any text in the format-string that is not a recognized
output code is passed through unchanged. This includes the "%"
character if it is not followed by a recognized format character.
For compatability with date(1), a
leading "+" character in the format-string will be ignored.
- If there are spaces or special characters in the string, it
must be quoted. The program will recognize most echo-like
escape conventions such as "\n" (newline) and "\t" (tab) in
format-string, and octal escapes (\0nn) are supported. If
only a day adjustment is specified, the default
format-string is "%x". If adjustment includes a time
element, the default format-string becomes
"%x-%R".
Adjustment specifications
Note that the sign ('+' or '-')
is required, but any field in the adjustment specification is
optional. If any of the numbers are missing, they default to zero.
If the unit specification is missing, it defaults to "d". The
program can figure out the full specification given enough syntax.
For example:
|
ADJUSTMENT
| EQUIVALENT
| MEANING
|
|
| -1-12
| -1-12:00
| Subtract one day and 12 hours
|
| +-3
| +0-3:00
| Add three hours
|
| -3:
| -0-3:00
| Subtract three hours
|
| -:30
| -0-0:30
| Subtract 30 minutes
|
| -2
| -2d
| Subtract two days
|
| +h
| +0h
| Add zero hours (don't alter date or
time) | |
Output format string specification
Format codes:
- %a
- Abbreviated day of week ("Tue")
- %A
- Full day of week ("Tuesday")
- %b
- Month name abbreviated to 3 chars ("Oct")
- %B
- Full month name ("October")
- %c
- Equivalent to "%a %b %e %R %Z %Y"
- %C
- Century ("19")
- %d
- Day of month ("13")
- %D
- Equivalent to "%d/%m/%y" ("%m/%d/%y" US)
- %e
- Equivalent to "% d" (pad with space)
- %f
- Equivalent to "%A, %B %-dth, %Y - %I:%M:%S %P"
- %F
- Equivalent to "%Y-%m-%d"
- %h
- Equivalent to "%b"
- %H
- Hour (24 hour)
- %I
- Hour (12 hour)
- %j
- Day of year ("123")
- %k
- Equivalent to "% H" (pad with space)
- %l
- Equivalent to "% I" (pad with space)
- %L
- Last day of month
- %m
- Month number ("10")
- %M
- Minute
- %n
- Equivalent to "\n" (newline).
- %p
- "AM" or "PM" for the hour
- %P
- "am" or "pm" for the hour
- %q
- "1" if daylight savings time is active, "0" if not.
- %r
- Equivalent to "%I:%M:%S %p"
- %R
- Equivalent to "%H:%M"
- %s
- Number of seconds since 01/01/1970-00:00.
- %S
- Seconds.
- %t
- Equivalent to "\t" (tab).
- %T
- Equivalent to "%H:%M:%S"
- %u
- Numeric day of week: 1-7 (1=Monday).
- %w
- Numeric day of week: 0-6 (0=Sunday).
- %x
- Equivalent to "%d/%m/%Y" ("%m/%d/%Y" US)
- %X
- Equivalent to "%H:%M:%S"
- %Y
- Full year, including century ("1989")
- %y
- Year of century ("89")
- %z
- Equivalent to "%d/%m/%y" ("%m/%d/%y" US) (no century)
- %Z
- Time zone ("PST")
- %%
- The "%" character
Code prefixes (dq-dq, dq_dq):
By default, yest pads numeric
fields with zeroes like date(1). It
also recognizes the following modifiers between % and a numeric
directive:
- '-' (hyphen) do not pad the field (i.e. "%-d")
'_' (underscore) pad the field with spaces (i.e. "%
m")
Code prefix (dq^dq):
Yest also recognizes the '^' (caret)
string modifier to use uppercase, if possible (i.e. "%^B").
Code suffix dqthdq:
Numeric format fields may be followed
with the modifier "th" (for example: "%dth"). This appends "st",
"nd", "rd", or "th", as appropriate, to the number.
EXAMPLES
Assuming the current date and time are:
- $ date
Tue May 9 21:09:07 EDT 2006
Display yesterday's date in the
default format.
- $ yest
05/08/2006
Generate the name of the sar file for 14 days ago:
- $ SARFILE=/var/adm/sa/sa`yest -14 %d`
$ echo $SARFILE
/var/adm/sa/sa25
Calculate the date an arbitrary number of days
from a specified date and display it with an extensive format:
- $ COUNT=+4 $ yest "The date is:\n\tThe %dth day of %B, %Y"
1988-12-28 $COUNT The date is:
The 1st day of January, 1989
Display
the date and time (default format) of three hours ago:
- $ yest -3h
05/09/2006-18:09
AUTHOR
Written by Kimball Hawkins
SEE ALSO
date (1)