curl_getdate(3)
π curl_getdate(3) β like, the whole entire manual, bestie
okay so this is curl_getdate(3), straight out of the Library Functions Manual, and it's genuinely one of those little functions that does way more than you'd expect. buckle up π
β¨ NAME β¨
curl_getdate β convert a date string into the number of seconds. yes literally just that. it eats a string, it spits out seconds. icon behavior π
π¦ SYNOPSIS π¦
#include <curl/curl.h>
time_t curl_getdate(const char *datestring, const time_t *now);
πΈ DESCRIPTION πΈ
so curl_getdate(3) returns the number of seconds since the Epoch β and the Epoch is January 1st 1970 00:00:00 in the UTC time zone β for whatever date and time the datestring param says. β°
the now parameter? not used. at all. just pass a NULL there and move on with your life π«Ά
and ngl, this function works with valid dates and does not always detect and reject wrong dates, such as February 30. so likeβ¦ it's not gonna call you out if you're being chaotic. it'll just vibe. π
π§ PARSING DATES AND TIMES π§
okay this is the fun part. a "date" is a string containing several items separated by whitespace, and the order of the items is immaterial β so you can basically throw them in whatever order and it'll still eat. no cap. a date string may contain many flavors of items:
π₯ calendar date items
can be specified several ways. here are the rules, and yes they're specific:
- month names can only be three-letter English abbreviations (so
Nov, notNovember) - numbers can be zero-prefixed
- the year may use 2 or 4 digits
- examples:
06 Nov 1994,06-Nov-94andNov-94 6
and the year math, since it's giving β¨arcane knowledgeβ¨:
- if the year appears to be below 100 (two-digit), any year after 70 is assumed to be 1900 + the given year
- all others are 2000 + the given year
so 94 β 1994 and 04 β 2004. slay, honestly.
β° time of the day items
this string specifies the time on a given day. the vibe check here is strict:
- you must specify it with 6 digits with two colons:
HH:MM:SS - if there is no time given in a provided date string,
00:00:00is assumed - example:
18:19:21
π time zone items
specifies international time zone. there are a few acronyms supported, but in general you should instead use the specific relative time compared to UTC. supported formats include: -1200, MST, +0100. π
π day of the week items
specifies a day of the week. the rules:
- days of the week may be spelled out in full (using English):
'Sunday','Monday', etc - or they may be abbreviated to their first three letters
- this is usually not info that adds anything π
π pure numbers
if a decimal number of the form YYYYMMDD appears, then YYYY is read as the year, MM as the month number and DD as the day of the month, for the specified calendar date. like 20040912 = September 12, 2004. cute and efficient β¨
π PROTOCOLS π
this functionality affects all supported protocols. every single one. π
β EXAMPLE β
here's the whole example, copied exactly because these strings are the whole point:
int main(void)
{
time_t t;
t = curl_getdate("Sun, 06 Nov 1994 08:49:37 GMT", NULL);
t = curl_getdate("Sunday, 06-Nov-94 08:49:37 GMT", NULL);
t = curl_getdate("Sun Nov 6 08:49:37 1994", NULL);
t = curl_getdate("06 Nov 1994 08:49:37 GMT", NULL);
t = curl_getdate("06-Nov-94 08:49:37 GMT", NULL);
t = curl_getdate("Nov 6 08:49:37 1994", NULL);
t = curl_getdate("06 Nov 1994 08:49:37", NULL);
t = curl_getdate("06-Nov-94 08:49:37", NULL);
t = curl_getdate("1994 Nov 6 08:49:37", NULL);
t = curl_getdate("GMT 08:49:37 06-Nov-94 Sunday", NULL);
t = curl_getdate("94 6 Nov 08:49:37", NULL);
t = curl_getdate("1994 Nov 6", NULL);
t = curl_getdate("06-Nov-94", NULL);
t = curl_getdate("Sun Nov 6 94", NULL);
t = curl_getdate("1994.Nov.6", NULL);
t = curl_getdate("Sun/Nov/6/94/GMT", NULL);
t = curl_getdate("Sun, 06 Nov 1994 08:49:37 CET", NULL);
t = curl_getdate("06 Nov 1994 08:49:37 EST", NULL);
t = curl_getdate("Sun, 12 Sep 2004 15:05:58 -0700", NULL);
t = curl_getdate("Sat, 11 Sep 2004 21:32:11 +0200", NULL);
t = curl_getdate("20040912 15:05:58 -0700", NULL);
t = curl_getdate("20040911 +0200", NULL);
}
look at all those formats just going off. main character energy fr fr π
π STANDARDS π
this parser handles date formats specified in:
- RFC 822 (including the update in RFC 1123) using time zone name or time zone delta
- RFC 850 (obsoleted by RFC 1036)
- ANSI C's
asctime()format
and like, these formats are the only ones RFC 7231 says HTTP applications may use. so if you were about to freestyle with a custom format? don't. π
π¦ AVAILABILITY π¦
added in curl 7.1. vintage but still iconic π
πΈ RETURN VALUE πΈ
so what do you get back:
- this function returns
-1when it fails to parse the date string - otherwise it returns the number of seconds as described above π
and now the time_t lore, which is genuinely important, pay attention:
- on systems with a signed 32-bit
time_t: if the year is larger than2037or less than1903, this function returns-1 - on systems with an unsigned 32-bit
time_t: if the year is larger than2106or less than1970, this function returns-1 - on systems with a 64-bit
time_t: if the year is less than1583, this function returns-1
and yeah, the reason for that last one: the Gregorian calendar was first introduced 1582, so no "real" dates in this way of doing dates existed before then. history lesson AND API docs, we contain multitudes π§ β¨
π₯ SEE ALSO π₯
that's the whole page, bestie β go parse some dates π
sign-off szn π«Ά this gem comes to you from libcurl, dated 2026-10-12 β mwah π
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms