1 .\" Copyright 2001 walter harms (walter.harms@informatik.uni-oldenburg.de)
2 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" Modified, 2001-12-26, aeb
28 .\" 2008-09-07, mtk, Various rewrites; added an example program.
30 .TH GETDATE 3 2014-06-13 "" "Linux Programmer's Manual"
32 getdate, getdate_r \- convert a date-plus-time string to broken-down time
34 .B "#include <time.h>"
36 .BI "struct tm *getdate(const char *" string );
38 .B "extern int getdate_err;"
40 .B "#include <time.h>"
42 .BI "int getdate_r(const char *" string ", struct tm *" res );
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
52 _XOPEN_SOURCE\ >=\ 500 ||
53 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
65 converts a string representation of a date and time,
66 contained in the buffer pointed to by
68 into a broken-down time.
69 The broken-down time is stored in a
71 structure, and a pointer to this
72 structure is returned as the function result.
75 structure is allocated in static storage,
76 and consequently it will be overwritten by further calls to
85 uses the formats found in the file
86 whose full pathname is given in the environment variable
88 The first line in the file that matches the given input string
89 is used for the conversion.
91 The matching is done case insensitively.
92 Superfluous whitespace, either in the pattern or in the string to
93 be converted, is ignored.
95 The conversion specifications that a pattern can contain are those given for
97 One more conversion specification is specified in POSIX.1-2001:
101 This is not implemented in glibc.
105 is given, the structure containing the broken-down time
106 is initialized with values corresponding to the current
107 time in the given timezone.
108 Otherwise, the structure is initialized to the broken-down time
109 corresponding to the current local time (as by a call to
112 When only the day of the week is given,
113 the day is taken to be the first such day
116 When only the month is given (and no year), the month is taken to
117 be the first such month equal to or after the current month.
118 If no day is given, it is the first day of the month.
120 When no hour, minute and second are given, the current
121 hour, minute and second are taken.
123 If no date is given, but we know the hour, then that hour is taken
124 to be the first such hour equal to or after the current hour.
127 is a GNU extension that provides a reentrant version of
129 Rather than using a global variable to report errors and a static buffer
130 to return the broken down time,
131 it returns errors via the function result value,
132 and returns the resulting broken-down time in the
133 caller-allocated buffer pointed to by the argument
138 returns a pointer to a
140 Otherwise, it returns NULL and sets the global variable
142 to one of the error numbers shown below.
150 on error it returns one of the error numbers shown below.
152 The following errors are returned via
156 or as the function result (for
162 environment variable is not defined, or its value is an empty string.
165 The template file specified by
167 cannot be opened for reading.
170 Failed to get file status information.
174 The template file is not a regular file.
177 An error was encountered while reading the template file.
180 Memory allocation failed (not enough memory available).
181 .\" Error 6 doesn't seem to occur in glibc
184 There is no line in the file that matches the input.
187 Invalid input specification.
191 File containing format patterns.
197 .SS Multithreading (see pthreads(7))
200 function is not thread-safe.
204 function is thread-safe.
208 The POSIX.1-2001 specification for
210 contains conversion specifications using the
214 modifier, while such specifications are not given for
220 so that precisely the same conversions are supported by both.
222 The program below calls
224 for each of its command-line arguments,
225 and for each call displays the values in the fields of the returned
228 The following shell session demonstrates the operation of the program:
232 .RB "$" " TFILE=$PWD/tfile"
233 .RB "$" " echo \(aq%A\(aq > $TFILE " " # Full name of the day of the week"
234 .RB "$" " echo \(aq%T\(aq >> $TFILE" " # ISO date (YYYY-MM-DD)"
235 .RB "$" " echo \(aq%F\(aq >> $TFILE" " # Time (HH:MM:SS)"
237 .RB "$" " export DATEMSK=$TFILE"
238 .RB "$" " ./a.out Tuesday \(aq2009-12-28\(aq \(aq12:22:33\(aq"
239 Sun Sep 7 06:03:36 CEST 2008
240 Call 1 ("Tuesday") succeeded:
250 Call 2 ("2009-12-28") succeeded:
260 Call 3 ("12:22:33") succeeded:
281 main(int argc, char *argv[])
286 for (j = 1; j < argc; j++) {
287 tmp = getdate(argv[j]);
290 printf("Call %d failed; getdate_err = %d\\n",
295 printf("Call %d (\\"%s\\") succeeded:\\n", j, argv[j]);
296 printf(" tm_sec = %d\\n", tmp\->tm_sec);
297 printf(" tm_min = %d\\n", tmp\->tm_min);
298 printf(" tm_hour = %d\\n", tmp\->tm_hour);
299 printf(" tm_mday = %d\\n", tmp\->tm_mday);
300 printf(" tm_mon = %d\\n", tmp\->tm_mon);
301 printf(" tm_year = %d\\n", tmp\->tm_year);
302 printf(" tm_wday = %d\\n", tmp\->tm_wday);
303 printf(" tm_yday = %d\\n", tmp\->tm_yday);
304 printf(" tm_isdst = %d\\n", tmp\->tm_isdst);