STRPTIME(1)

πŸ“¦
version 0.4.10 Β· 2 versions
, in debian bookworm

πŸ’– STRPTIME πŸ’–

okay so bestie, this is the manual page for the strptime command from the dateutils fam, and I'm gonna walk you through every single crumb of it like we're texting at 2am 🫢 no skipping, no summarizing, we're doing the whole thing πŸ’…


🌸 NAME 🌸

strptime β€” parse input from stdin according to one of the given formats, the FORMATs. that's the vibe, that's the job πŸŽ€

πŸ¦‹ SYNOPSIS πŸ¦‹

strptime [OPTION]...  [INPUT]...

✨ DESCRIPTION ✨

so like, strptime parses input from stdin according to one of the given formats, the FORMATs. the format string specifiers are literally the same ones as for strptime(3), so if you already know those you're already winning πŸ’…

here are the OPTIONs it recognizes:

πŸ‘‘ OPTIONS πŸ‘‘

  • -h, --help β€” prints help and then dips out (exits).
  • -V, --version β€” prints the version and then dips out too.
  • -t, --time β€” also shows the time in the output. by default it just shows the date, no clock energy.
  • -q, --quiet β€” suppresses the message about date/time and duration parser errors. like, shhh 🀫
  • -f, --format=STRING β€” the output format. this can either be a specifier string (similar to strftime()'s FMT) or the name of a calendar.
  • -i, --input-format=STRING... β€” the input format, and yes you can use it multiple times πŸ”₯ each date/time gets passed to the input format parsers in the order they're given, and if a date/time can be read successfully with a given input format specifier string, that value gets used. first one to hit, wins.
  • -e, --backslash-escapes β€” turns on interpretation of backslash escapes in the output and input format specifier strings. spooky little slashes get meaning now ✨
  • -l, --locale β€” makes the internal strptime(3) and strftime(3) behave in a locale dependent way. default is to pretend LC_ALL=C is in place, so it's fake-C-coded unless you say otherwise.

πŸŽ€ FORMAT SPECS πŸŽ€

format specs in dateutils are similar to posix's strftime(). but β€” and this is the tea β€” because dateutils supports a way broader range of calendars, it has to employ different rules. so don't come in here expecting pure posix behavior, bestie 🫠

🌈 Date specs

  • %a β€” the abbreviated weekday name
  • %A β€” the full weekday name
  • %_a β€” the weekday name shortened to a single character (MTWRFAS)
  • %b β€” the abbreviated month name
  • %B β€” the full month name
  • %_b β€” the month name shortened to a single character (FGHJKMNQUVXZ)
  • %c β€” the count of the weekday within the month (range 00 to 05)
  • %C β€” the count of the weekday within the year (range 00 to 53)
  • %d β€” the day of the month, 2 digits (range 00 to 31)
  • %D β€” the day of the year, 3 digits (range 000 to 366)
  • %F β€” equivalent to %Y-%m-%d (ymd's canonical format, iconic)
  • %g β€” ISO week date year without the century (range 00 to 99)
  • %G β€” ISO week date year including the century
  • %j β€” equivalent to %D
  • %m β€” the month in the current calendar (range 00 to 12)
  • %Q β€” the quarter of the year (range Q1 to Q4)
  • %q β€” the number of the quarter (range 01 to 04)
  • %s β€” the number of seconds since the Epoch.
  • %u β€” the weekday as number (range 01 to 07, Sunday being 07)
  • %U β€” the week count, day of week is Sun (range 00 to 53)
  • %V β€” the ISO week count, day of week is Mon (range 01 to 53)
  • %w β€” the weekday as number (range 00 to 06, Sunday being 00)
  • %W β€” the week count, day of week is Mon (range 00 to 53)
  • %y β€” the year without a century (range 00 to 99)
  • %Y β€” the year including the century
  • %_y β€” the year shortened to a single digit
  • %Z β€” the zone offset in hours and minutes (HH:MM) with a preceding sign (+ for offsets east of UTC, - for offsets west of UTC)

and now the roman numeral girlies πŸ›οΈ

  • %Od β€” the day as roman numerals
  • %Om β€” the month as roman numerals
  • %Oy β€” the two digit year as roman numerals
  • %OY β€” the year including the century as roman numerals
  • %rs β€” in time systems whose Epoch is different from the unix Epoch, this selects the number of seconds since then.
  • %rY β€” in calendars with years that don't coincide with the Gregorian years, this selects the calendar's year.
  • %dth β€” the day of the month as an ordinal number, 1st, 2nd, 3rd, etc.
  • %mth β€” the month of the year as an ordinal number, 1st, 2nd, 3rd, etc.
  • %db β€” the business day of the month (since last month's ultimo)
  • %dB β€” number of business days until this month's ultimo

⏰ Time specs

  • %H β€” the hour of the day using a 24h clock, 2 digits (range 00 to 23)
  • %I β€” the hour of the day using a 12h clock, 2 digits (range 01 to 12)
  • %M β€” the minute (range 00 to 59)
  • %N β€” the nanoseconds (range 000000000 to 999999999)
  • %p β€” the string AM or PM, noon is PM and midnight is AM.
  • %P β€” like %p but in lowercase
  • %S β€” The (range 00 to 60, 60 is for leap seconds). yes bestie the original really does just say "The" there and then move on, I'm keeping it πŸ’― as written, no editing the source fr fr
  • %T β€” equivalent to %H:%M:%S

πŸ’« General specs

  • %n β€” a newline character
  • %t β€” a tab character
  • %% β€” a literal % character

🧚 Modifiers

  • %O β€” modifier to turn decimal numbers into Roman numerals
  • %r β€” modifier to turn units into real units
  • %0 β€” modifier to turn on zero prefixes
  • %SPC β€” modifier to turn on space prefixes
  • %- β€” modifier to turn off prefixes altogether
  • th β€” suffix, read and print ordinal numbers
  • b β€” suffix, treat days as business days
by design, dates before 1601-01-01 are not supported. so don't even try it, bestie, it's not a glitch it's a design choice 😭

for conformity, here's a list of calendar designators and their corresponding format string:

  • ymd β€” %Y-%m-%d
  • ymcw β€” %Y-%m-%c-%w
  • ywd β€” %rY-W%V-%u
  • bizda β€” %Y-%m-%db
  • lilian β€” n/a
  • ldn β€” n/a
  • julian β€” n/a
  • jdn β€” n/a
  • matlab β€” n/a
  • mdn β€” n/a

these designators can be used as output format string, and moreover, @code{lilian}/@code{ldn} and @code{julian}/@code{jdn} can also be used as input format string. (yes those @code{} bits are literally in the source, texinfo leaks and all, we don't gatekeep πŸ™ˆ)


πŸ”₯ EXAMPLES πŸ”₯

$ strptime -i '%a, %b-%d/%Y' 'Mon, May-01/2000'
2000-05-01
$

and the stdin version, because why type twice:

$ strptime -i '%a, %b-%d/%Y' <<EOF
Mon, May-01/2000
Mon, Mar-2/2000
EOF
2000-05-01
2000-03-02
$

look at that. parsed. slayed. ✨


πŸ’œ AUTHOR πŸ’œ

written by Sebastian Freundt <freundt@fresse.org> β€” the icon, the legend πŸ‘‘

πŸ› REPORTING BUGS πŸ›

report bugs to: https://github.com/hroptatyr/dateutils/issues

πŸ¦‹ SEE ALSO πŸ¦‹

the full documentation for strptime is maintained as a Texinfo manual. if the info and strptime programs are properly installed at your site, the command

info (dateutils)strptime

should give you access to the complete manual. go read it, it's giving reference material πŸ’…


dateutils 0.4.10 Β· February 2023 β€” that's the version and the date bestie, straight from the footer, mwah πŸ’– stay parsed, stay iconic, periodt πŸŒˆπŸŽ€βœ¨

πŸ“¦ where this page comes from