2 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\" This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH GETDATE 3C "Nov 1, 2003"
14 getdate \- convert user format date and time
20 \fBstruct tm *\fR\fBgetdate\fR(\fBconst char *\fR\fIstring\fR);
21 extern int getdate_err;
27 The \fBgetdate()\fR function converts user-definable date and/or time
28 specifications pointed to by \fIstring\fR to a \fBtm\fR structure. The \fBtm\fR
29 structure is defined in the <\fBtime.h\fR> header.
32 User-supplied templates are used to parse and interpret the input string. The
33 templates are text files created by the user and identified via the
34 environment variable \fBDATEMSK\fR. Each line in the template represents an
35 acceptable date and/or time specification using conversion specifications
36 similar to those used by \fBstrftime\fR(3C) and \fBstrptime\fR(3C). Dates
37 before 1902 and after 2037 are illegal. The first line in the template that
38 matches the input specification is used for interpretation and conversion into
39 the internal time format.
40 .SS "Conversion Specifications"
43 The following conversion specifications are supported:
59 Locale's abbreviated weekday name.
68 Locale's full weekday name.
77 Locale's abbreviated month name.
86 Locale's full month name.
95 Locale's appropriate date and time representation.
104 Century number (the year divided by 100 and truncated to an integer as a
105 decimal number [1,99]); single digits are preceded by 0; see
106 \fBstandards\fR(5). If used without the \fB%y\fR specifier, this format
107 specifier will assume the current year offset in whichever century is
108 specified. The only valid years are between 1902-2037.
117 day of month [01,31]; leading zero is permitted but not required.
126 Date as \fB%m\fR/\fB%d\fR/\fB%y\fR.
144 Locale's abbreviated month name.
153 Hour (24-hour clock) [0,23]; leading zero is permitted but not required.
162 Hour (12-hour clock) [1,12]; leading zero is permitted but not required.
171 Day number of the year [1,366]; leading zeros are permitted but not required.
180 Month number [1,12]; leading zero is permitted but not required.
189 Minute [0,59]; leading zero is permitted but not required.
207 Locale's equivalent of either a.m. or p.m.
216 Appropriate time representation in the 12-hour clock format with \fB%p\fR.
225 Time as \fB%H\fR:\fB%M\fR.
235 Seconds [0,60]; leading zero is permitted but not required. The range of values
236 is [00,60] rather than [00,59] to allow for the occasional leap second.
239 .SS "Default and other standards"
246 Seconds [0,61]; leading zero is permitted but not required. The range of values
247 is [00,61] rather than [00,59] to allow for the occasional leap second and even
248 more occasional double leap second.
266 Time as \fB%H\fR:\fB%M\fR:\fB%S\fR.
275 Week number of the year as a decimal number [0,53], with Sunday as the first
276 day of the week; leading zero is permitted but not required.
285 Weekday as a decimal number [0,6], with 0 representing Sunday.
294 Week number of the year as a decimal number [0,53], with Monday as the first
295 day of the week; leading zero is permitted but not required.
304 Locale's appropriate date representation.
313 Locale's appropriate time representation.
322 Year within century. When a century is not otherwise specified, values in the
323 range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive);
324 values in the range 00-68 refer to years in the twenty-first century (2000 to
334 Year, including the century (for example, 1993).
343 Time zone name or no characters if no time zone exists.
346 .SS "Modified Conversion Specifications"
349 Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
350 modifier characters to indicate that an alternative format or specification
351 should be used rather than the one normally used by the unmodified
352 specification. If the alternative format or specification does not exist in the
353 current locale, the behavior be as if the unmodified conversion specification
361 Locale's alternative appropriate date and time representation.
370 Name of the base year (period) in the locale's alternative representation.
379 Locale's alternative date representation.
388 Locale's alternative time representation.
397 Offset from \fB%EC\fR (year only) in the locale's alternative representation.
406 Full alternative year representation.
415 Day of the month using the locale's alternative numeric symbols; leading zeros
416 are permitted but not required.
434 Hour (24-hour clock) using the locale's alternative numeric symbols.
443 Hour (12-hour clock) using the locale's alternative numeric symbols.
452 Month using the locale's alternative numeric symbols.
461 Minutes using the locale's alternative numeric symbols.
470 Seconds using the locale's alternative numeric symbols.
479 Week number of the year (Sunday as the first day of the week) using the
480 locale's alternative numeric symbols.
489 Number of the weekday (Sunday=0) using the locale's alternative numeric
499 Week number of the year (Monday as the first day of the week) using the
500 locale's alternative numeric symbols.
509 Year (offset from \fB%C\fR) in the locale's alternative representation and
510 using the locale's alternative numeric symbols.
513 .SS "Internal Format Conversion"
516 The following rules are applied for converting the input specification into the
522 If only the weekday is given, today is assumed if the given day is equal to the
523 current day and next week if it is less.
529 If only the month is given, the current month is assumed if the given month is
530 equal to the current month and next year if it is less and no year is given.
531 (The first day of month is assumed if no day is given.)
537 If only the year is given, the values of the \fBtm_mon\fR, \fBtm_mday\fR,
538 \fBtm_yday\fR, \fBtm_wday\fR, and \fBtm_isds\fRt members of the returned
539 \fBtm\fR structure are not specified.
545 If the century is given, but the year within the century is not given, the
546 current year within the century is assumed.
552 If no hour, minute, and second are given, the current hour, minute, and second
559 If no date is given, today is assumed if the given hour is greater than the
560 current hour and tomorrow is assumed if it is less.
562 .SS "General Specifications"
565 A conversion specification that is an ordinary character is executed by
566 scanning the next character from the buffer. If the character scanned from the
567 buffer differs from the one comprising the conversion specification, the
568 specification fails, and the differing and subsequent characters remain
572 A series of conversion specifications composed of \fB%n\fR, \fB%t\fR, white
573 space characters, or any combination is executed by scanning up to the first
574 character that is not white space (which remains unscanned), or until no more
575 characters can be scanned.
578 Any other conversion specification is executed by scanning characters until a
579 character matching the next conversion specification is scanned, or until no
580 more characters can be scanned. These characters, except the one matching the
581 next conversion specification, are then compared to the locale values
582 associated with the conversion specifier. If a match is found, values for the
583 appropriate \fItm\fR structure members are set to values corresponding to the
584 locale information. If no match is found, \fBgetdate()\fR fails and no more
585 characters are scanned.
588 The month names, weekday names, era names, and alternative numeric symbols can
589 consist of any combination of upper and lower case letters. The user can
590 request that the input date or time specification be in a specific language by
591 setting the \fBLC_TIME\fR category using \fBsetlocale\fR(3C).
595 If successful, \fBgetdate()\fR returns a pointer to a \fBtm\fR structure;
596 otherwise, it returns \fINULL\fR and sets the global variable \fBgetdate_err\fR
597 to indicate the error. Subsequent calls to \fBgetdate()\fR alter the contents
598 of \fBgetdate_err\fR.
601 The following is a complete list of the \fBgetdate_err\fR settings and their
609 The \fBDATEMSK\fR environment variable is null or undefined.
618 The template file cannot be opened for reading.
627 Failed to get file status information.
636 The template file is not a regular file.
645 An error is encountered while reading the template file.
654 The \fBmalloc()\fR function failed (not enough memory is available).
663 There is no line in the template that matches the input.
672 The input specification is invalid (for example, \fBFebruary 31\fR).
678 The \fBgetdate()\fR function makes explicit use of macros described on the
679 \fBctype\fR(3C) manual page.
682 \fBExample 1 \fRExamples of the \fBgetdate()\fR function.
685 The following example shows the possible contents of a template:
691 %A %B %d %Y, %H:%M:%S
696 at %A the %dst of %B in %Y
697 run job at %I %p,%B %dnd
698 %A den %d. %B %Y %H.%M Uhr
704 The following are examples of valid input specifications for the above
710 getdate("10/1/87 4 PM")
712 getdate("Friday September 19 1987, 10:30:30")
713 getdate("24,9,1986 10:30")
714 getdate("at monday the 1st of december in 1986")
715 getdate("run job at 3 PM, december 2nd")
721 If the \fBLANG\fR environment variable is set to \fBde\fR (German), the
727 getdate("freitag den 10. oktober 1986 10.30 Uhr")
733 Local time and date specification are also supported. The following examples
734 show how local date and time specification can be defined in the template.
743 Invocation Line in Template
745 getdate("11/27/86") %m/%d/%y
746 getdate("27.11.86") %d.%m.%y
747 getdate("86-11-27") %y-%m-%d
748 getdate("Friday 12:00:00") %A %H:%M:%S
753 The following examples illustrate the Internal Format Conversion rules. Assume
754 that the current date is Mon Sep 22 12:19:47 EDT 1986 and the \fBLANG\fR
755 environment variable is not set.
764 Input Template Line Date
766 \fBMon\fR \fB%a\fR Mon Sep 22 12:19:48 EDT 1986
767 \fBSun\fR \fB%a\fR Sun Sep 28 12:19:49 EDT 1986
768 \fBFri\fR \fB%a\fR Fri Sep 26 12:19:49 EDT 1986
769 \fBSeptember\fR \fB%B\fR Mon Sep 1 12:19:49 EDT 1986
770 \fBJanuary\fR \fB%B\fR Thu Jan 1 12:19:49 EST 1987
771 \fBDecember\fR \fB%B\fR Mon Dec 1 12:19:49 EDT 1986
772 \fBSep Mon\fR \fB%b %a\fR Mon Sep 1 12:19:50 EDT 1986
773 \fBJan Fri\fR \fB%b %a\fR Fri Jan 2 12:19:50 EST 1987
774 \fBDec Mon\fR \fB%b %a\fR Mon Dec 1 12:19:50 EST 1986
775 \fBJan Wed 1989\fR \fB%b\fR \fB%a\fR \fB%Y\fR Wed Jan 4 12:19:51 EST 1989
776 \fBFri 9\fR \fB%a %H\fR Fri Sep 26 09:00:00 EDT 1986
777 \fBFeb 10:30\fR \fB%b %H:%S\fR Sun Feb 1 10:00:30 EST 1987
778 \fB10:30\fR \fB%H:%M\fR Tue Sep 23 10:30:00 EDT 1986
779 \fB13:30\fR \fB%H:%M\fR Mon Sep 22 13:30:00 EDT 1986
785 See \fBattributes\fR(5) for descriptions of the following attributes:
793 ATTRIBUTE TYPE ATTRIBUTE VALUE
797 Interface Stability Standard
805 \fBctype\fR(3C), \fBmktime\fR(3C), \fBsetlocale\fR(3C), \fBstrftime\fR(3C),
806 \fBstrptime\fR(3C), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)