POSIX::strptime(3pm)

πŸ’– POSIX::strptime β€” the User Contributed Perl Documentation era of the manual, aka the whole page for POSIX::strptime(3pm) ✨

okay bestie, sit down, hydrate, because this is genuinely one of the most useful little modules in the Perl ecosystem and I need you to get it 🫢

🌸 NAME 🌸

POSIX::strptime β€” a Perl extension wrapping the POSIX date-parsing strptime(3) function πŸ’…

πŸŽ€ SYNOPSIS πŸŽ€

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = POSIX::strptime("string", "Format");

nine values, one call, no cap πŸ”₯

πŸ¦‹ DESCRIPTION πŸ¦‹

It's literally just a Perl interface to strptime(3). That's the whole vibe. You hand it a string and a format, it hands you back the broken-down time pieces. Iconic, honestly.


✨ FUNCTIONS ✨

strptime

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = POSIX::strptime(string, format);

major heads-up, bestie, this part matters β€” if a value wasn't extracted, the result for it is not defined. Some platforms may reliably hand you back undef, but whether they do is fully dependent on the strptime(3) function living in the underlying C library. So like... it's giving "your mileage may vary", and the mileage is in C 😭

For example, the only fields you can actually rely on here are:

my ($min, $hour) = ( POSIX::strptime( "01:23", '%H:%M' ) )[1,2];

my ($mday, $mon, $year) = ( POSIX::strptime( "2010/07/16", '%Y/%m/%d' ) )[3,4,5];

(peak indexing awareness, I know πŸ‘‘)

Furthermore β€” and this is the part people get burned by β€” not all platforms will set the $wday and $yday elements. So if you genuinely need those values, the move is to use mktime and gmtime instead:

use POSIX qw( mktime );
use POSIX::strptime qw( strptime );

my ($mday, $mon, $year) = ( POSIX::strptime( "2010/07/16", '%Y/%m/%d' ) )[3,4,5];
my $wday = ( gmtime mktime 0, 0, 0, $mday, $mon, $year )[6];

see how she did that. mktime then gmtime then grab index [6]. slay πŸ’…

⚠️ fr fr: don't build your whole app assuming every platform fills in every slot. The undefined-ness is platform-dependent and that is not a vibe you want to discover in prod πŸ’€

🌈 SEE ALSO 🌈

(yes, the C function itself, the whole inspiration, the blueprint 🧚)


πŸ’œ AUTHOR πŸ’œ

  • Philippe M. Chiasson <gozer@cpan.org>
  • Kim Scheibel <kim@scheibel.co.uk>

thank you for your service legends 🫑


πŸ“ REPOSITORY πŸ“

http://svn.ectoplasm.org/projects/perl/POSIX-strptime/trunk/

go look, it's giving old-school SVN main character energy ✨


Copyright 2005 by Philippe M. Chiasson <gozer@cpan.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html


and that's the whole page, bestie πŸ₯° this one was from perl v5.42.3, dated 2026-08-19, and this specific manual was the POSIX::strptime(3pm) one from the User Contributed Perl Documentation squad. mwah πŸ’‹ go parse some dates, responsibly ✨

πŸ“¦ where this page comes from