{"id":6906,"date":"2022-12-20T19:34:18","date_gmt":"2022-12-20T22:34:18","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/getdate-man3\/"},"modified":"2022-12-20T19:34:18","modified_gmt":"2022-12-20T22:34:18","slug":"getdate-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/getdate-man3\/","title":{"rendered":"GETDATE (man3)"},"content":{"rendered":"<h1 align=\"center\">GETDATE<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#ENVIRONMENT\">ENVIRONMENT<\/a><br \/> <a href=\"#ATTRIBUTES\">ATTRIBUTES<\/a><br \/> <a href=\"#CONFORMING TO\">CONFORMING TO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">getdate, getdate_r \u2212 convert a date-plus-time string to broken-down time<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <time.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>struct tm *getdate(const char *<\/b><i>string<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>extern int getdate_err;<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <time.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int getdate_r(const char *<\/b><i>string<\/i><b>, struct tm *<\/b><i>res<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:5%; margin-top: 1em\">Feature Test Macro Requirements for glibc (see <b>feature_test_macros<\/b>(7)):<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>getdate<\/b>():<\/p>\n<p style=\"margin-left:17%;\">_XOPEN_SOURCE\u00a0>=\u00a0500<\/p>\n<p style=\"margin-left:11%;\"><b>getdate_r<\/b>():<\/p>\n<p style=\"margin-left:17%;\">_GNU_SOURCE<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The function <b>getdate<\/b>() converts a string representation of a date and time, contained in the buffer pointed to by <i>string<\/i>, into a broken-down time. The broken-down time is stored in a <i>tm<\/i> structure, and a pointer to this structure is returned as the function result. This <i>tm<\/i> structure is allocated in static storage, and consequently it will be overwritten by further calls to <b>getdate<\/b>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In contrast to <b>strptime<\/b>(3), (which has a <i>format<\/i> argument), <b>getdate<\/b>() uses the formats found in the file whose full pathname is given in the environment variable <b>DATEMSK<\/b>. The first line in the file that matches the given input string is used for the conversion.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The matching is done case insensitively. Superfluous whitespace, either in the pattern or in the string to be converted, is ignored.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The conversion specifications that a pattern can contain are those given for <b>strptime<\/b>(3). One more conversion specification is specified in POSIX.1-2001:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p><b>%Z<\/b><\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"75%\">\n<p>Timezone name. This is not implemented in glibc.<\/p>\n<\/td>\n<td width=\"3%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">When <b>%Z<\/b> is given, the structure containing the broken-down time is initialized with values corresponding to the current time in the given timezone. Otherwise, the structure is initialized to the broken-down time corresponding to the current local time (as by a call to <b>localtime<\/b>(3)).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When only the day of the week is given, the day is taken to be the first such day on or after today.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When only the month is given (and no year), the month is taken to be the first such month equal to or after the current month. If no day is given, it is the first day of the month.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When no hour, minute and second are given, the current hour, minute and second are taken.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If no date is given, but we know the hour, then that hour is taken to be the first such hour equal to or after the current hour.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>getdate_r<\/b>() is a GNU extension that provides a reentrant version of <b>getdate<\/b>(). Rather than using a global variable to report errors and a static buffer to return the broken down time, it returns errors via the function result value, and returns the resulting broken-down time in the caller-allocated buffer pointed to by the argument <i>res<\/i>.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">When successful, <b>getdate<\/b>() returns a pointer to a <i>struct tm<\/i>. Otherwise, it returns NULL and sets the global variable <i>getdate_err<\/i> to one of the error numbers shown below. Changes to <i>errno<\/i> are unspecified.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">On success <b>getdate_r<\/b>() returns 0; on error it returns one of the error numbers shown below.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following errors are returned via <i>getdate_err<\/i> (for <b>getdate<\/b>()) or as the function result (for <b>getdate_r<\/b>()):<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\"><b>1<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p style=\"margin-top: 1em\">The <b>DATEMSK<\/b> environment variable is not defined, or its value is an empty string.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p><b>2<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>The template file specified by <b>DATEMSK<\/b> cannot be opened for reading.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p><b>3<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>Failed to get file status information.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p><b>4<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>The template file is not a regular file.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p><b>5<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>An error was encountered while reading the template file.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p><b>6<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>Memory allocation failed (not enough memory available).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p><b>7<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>There is no line in the file that matches the input.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p><b>8<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"83%\">\n<p>Invalid input specification.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>ENVIRONMENT <a name=\"ENVIRONMENT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>DATEMSK<\/b><\/p>\n<p style=\"margin-left:22%;\">File containing format patterns.<\/p>\n<p style=\"margin-left:11%;\"><b>TZ<\/b>, <b>LC_TIME<\/b><\/p>\n<p style=\"margin-left:22%;\">Variables used by <b>strptime<\/b>(3).<\/p>\n<h2>ATTRIBUTES <a name=\"ATTRIBUTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">For an explanation of the terms used in this section, see <b>attributes<\/b>(7).<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-1654201.png\" alt=\"Image grohtml-1654201.png\"><\/p>\n<h2>CONFORMING TO <a name=\"CONFORMING TO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">POSIX.1-2001, POSIX.1-2008.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The POSIX.1 specification for <b>strptime<\/b>(3) contains conversion specifications using the <b>%E<\/b> or <b>%O<\/b> modifier, while such specifications are not given for <b>getdate<\/b>(). In glibc, <b>getdate<\/b>() is implemented using <b>strptime<\/b>(3), so that precisely the same conversions are supported by both.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The program below calls <b>getdate<\/b>() for each of its command-line arguments, and for each call displays the values in the fields of the returned <i>tm<\/i> structure. The following shell session demonstrates the operation of the program:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">$ <b>TFILE=$PWD\/tfile<\/b> <br \/> $ <b>echo &#8216;%A&#8217; > $TFILE<\/b> # Full name of the day of the week <br \/> $ <b>echo &#8216;%T&#8217; >> $TFILE<\/b> # ISO date (YYYY-MM-DD) <br \/> $ <b>echo &#8216;%F&#8217; >> $TFILE<\/b> # Time (HH:MM:SS) <br \/> $ <b>date<\/b> <br \/> $ <b>export DATEMSK=$TFILE<\/b> <br \/> $ <b>.\/a.out Tuesday &#8216;2009-12-28&#8242; &#8217;12:22:33&#8217;<\/b> <br \/> Sun Sep 7 06:03:36 CEST 2008 <br \/> Call 1 (&#8220;Tuesday&#8221;) succeeded: <br \/> tm_sec = 36 <br \/> tm_min = 3 <br \/> tm_hour = 6 <br \/> tm_mday = 9 <br \/> tm_mon = 8 <br \/> tm_year = 108 <br \/> tm_wday = 2 <br \/> tm_yday = 252 <br \/> tm_isdst = 1 <br \/> Call 2 (&#8220;2009-12-28&#8221;) succeeded: <br \/> tm_sec = 36 <br \/> tm_min = 3 <br \/> tm_hour = 6 <br \/> tm_mday = 28 <br \/> tm_mon = 11 <br \/> tm_year = 109 <br \/> tm_wday = 1 <br \/> tm_yday = 361 <br \/> tm_isdst = 0 <br \/> Call 3 (&#8220;12:22:33&#8221;) succeeded: <br \/> tm_sec = 33 <br \/> tm_min = 22 <br \/> tm_hour = 12 <br \/> tm_mday = 7 <br \/> tm_mon = 8 <br \/> tm_year = 108 <br \/> tm_wday = 0 <br \/> tm_yday = 250 <br \/> tm_isdst = 1<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Program source<\/b> <br \/> #define _GNU_SOURCE <br \/> #include <time.h> <br \/> #include <stdio.h> <br \/> #include <stdlib.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <br \/> main(int argc, char *argv[]) <br \/> { <br \/> struct tm *tmp;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">for (int j = 1; j < argc; j++) { <br \/> tmp = getdate(argv[j]);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">if (tmp == NULL) { <br \/> printf(&#8220;Call %d failed; getdate_err = %dn&#8221;, <br \/> j, getdate_err); <br \/> continue; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">printf(&#8220;Call %d (&#8220;%s&#8221;) succeeded:n&#8221;, j, argv[j]); <br \/> printf(&#8221; tm_sec = %dn&#8221;, tmp\u2212>tm_sec); <br \/> printf(&#8221; tm_min = %dn&#8221;, tmp\u2212>tm_min); <br \/> printf(&#8221; tm_hour = %dn&#8221;, tmp\u2212>tm_hour); <br \/> printf(&#8221; tm_mday = %dn&#8221;, tmp\u2212>tm_mday); <br \/> printf(&#8221; tm_mon = %dn&#8221;, tmp\u2212>tm_mon); <br \/> printf(&#8221; tm_year = %dn&#8221;, tmp\u2212>tm_year); <br \/> printf(&#8221; tm_wday = %dn&#8221;, tmp\u2212>tm_wday); <br \/> printf(&#8221; tm_yday = %dn&#8221;, tmp\u2212>tm_yday); <br \/> printf(&#8221; tm_isdst = %dn&#8221;, tmp\u2212>tm_isdst); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">exit(EXIT_SUCCESS); <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>time<\/b>(2), <b>localtime<\/b>(3), <b>setlocale<\/b>(3), <b>strftime<\/b>(3), <b>strptime<\/b>(3)<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  getdate, getdate_r \u2212 convert a date-plus-time string to broken-down time <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,2086,3007],"class_list":["post-6906","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-getdate","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6906"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6906\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}