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, not November)
  • numbers can be zero-prefixed
  • the year may use 2 or 4 digits
  • examples: 06 Nov 1994, 06-Nov-94 and Nov-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:00 is 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:

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 -1 when 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 than 2037 or less than 1903, this function returns -1
  • on systems with an unsigned 32-bit time_t: if the year is larger than 2106 or less than 1970, this function returns -1
  • on systems with a 64-bit time_t: if the year is less than 1583, 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