FAQ 4.18 Does Perl have a Year 2000 problem? Is Perl Y2K compliant?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .


4.18: Does Perl have a Year 2000 problem? Is Perl Y2K compliant?

    Short answer: No, Perl does not have a Year 2000 problem. Yes, Perl is
    Y2K compliant (whatever that means). The programmers you've hired to use
    it, however, probably are not.

    Long answer: The question belies a true understanding of the issue. Perl
    is just as Y2K compliant as your pencil--no more, and no less. Can you
    use your pencil to write a non-Y2K-compliant memo? Of course you can. Is
    that the pencil's fault? Of course it isn't.

    The date and time functions supplied with Perl (gmtime and localtime)
    supply adequate information to determine the year well beyond 2000 (2038
    is when trouble strikes for 32-bit machines). The year returned by these
    functions when used in a list context is the year minus 1900. For years
    between 1910 and 1999 this *happens* to be a 2-digit decimal number. To
    avoid the year 2000 problem simply do not treat the year as a 2-digit
    number. It isn't.

    When gmtime() and localtime() are used in scalar context they return a
    timestamp string that contains a fully-expanded year. For example,
    "$timestamp = gmtime(1005613200)" sets $timestamp to "Tue Nov 13
    01:00:00 2001". There's no year 2000 problem here.

    That doesn't mean that Perl can't be used to create non-Y2K compliant
    programs. It can. But so can your pencil. It's the fault of the user,
    not the language. At the risk of inflaming the NRA: "Perl doesn't break
    Y2K, people do." See http://www.perl.org/about/y2k.html for a longer


The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in

Site Timeline