{
    "content": [
        {
            "type": "text",
            "text": "# date (perldoc)\n\n## Sections\n\n- **Found in /usr/share/perl/5.34/pod/perlfaq4.pod**\n- **Found in /usr/share/perl/5.34/pod/perlfaq5.pod**\n- **Found in /usr/share/perl/5.34/pod/perlfaq8.pod**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "date",
        "section": "-q",
        "mode": "perldoc",
        "summary": null,
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "Found in /usr/share/perl/5.34/pod/perlfaq4.pod",
                "lines": 93,
                "subsections": []
            },
            {
                "name": "Found in /usr/share/perl/5.34/pod/perlfaq5.pod",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "Found in /usr/share/perl/5.34/pod/perlfaq8.pod",
                "lines": 14,
                "subsections": []
            }
        ],
        "sections": {
            "Found in /usr/share/perl/5.34/pod/perlfaq4.pod": {
                "content": "How can I compare two dates and find the difference?\n(contributed by brian d foy)\n\nYou could just store all your dates as a number and then subtract. Life\nisn't always that simple though.\n\nThe Time::Piece module, which comes with Perl, replaces localtime with a\nversion that returns an object. It also overloads the comparison\noperators so you can compare them directly:\n\nuse Time::Piece;\nmy $date1 = localtime( $sometime );\nmy $date2 = localtime( $someothertime );\n\nif( $date1 < $date2 ) {\nprint \"The date was in the past\\n\";\n}\n\nYou can also get differences with a subtraction, which returns a\nTime::Seconds object:\n\nmy $datediff = $date1 - $date2;\nprint \"The difference is \", $datediff->days, \" days\\n\";\n\nIf you want to work with formatted dates, the Date::Manip, Date::Calc,\nor DateTime modules can help you.\n\nHow do I find yesterday's date?\n(contributed by brian d foy)\n\nTo do it correctly, you can use one of the \"Date\" modules since they\nwork with calendars instead of times. The DateTime module makes it\nsimple, and give you the same time of day, only the day before, despite\ndaylight saving time changes:\n\nuse DateTime;\n\nmy $yesterday = DateTime->now->subtract( days => 1 );\n\nprint \"Yesterday was $yesterday\\n\";\n\nYou can also use the Date::Calc module using its \"TodayandNow\"\nfunction.\n\nuse Date::Calc qw( TodayandNow AddDeltaDHMS );\n\nmy @datetime = AddDeltaDHMS( TodayandNow(), -1, 0, 0, 0 );\n\nprint \"@datetime\\n\";\n\nMost people try to use the time rather than the calendar to figure out\ndates, but that assumes that days are twenty-four hours each. For most\npeople, there are two days a year when they aren't: the switch to and\nfrom summer time throws this off. For example, the rest of the\nsuggestions will be wrong sometimes:\n\nStarting with Perl 5.10, Time::Piece and Time::Seconds are part of the\nstandard distribution, so you might think that you could do something\nlike this:\n\nuse Time::Piece;\nuse Time::Seconds;\n\nmy $yesterday = localtime() - ONEDAY; # WRONG\nprint \"Yesterday was $yesterday\\n\";\n\nThe Time::Piece module exports a new \"localtime\" that returns an object,\nand Time::Seconds exports the \"ONEDAY\" constant that is a set number of\nseconds. This means that it always gives the time 24 hours ago, which is\nnot always yesterday. This can cause problems around the end of daylight\nsaving time when there's one day that is 25 hours long.\n\nYou have the same problem with Time::Local, which will give the wrong\nanswer for those same special cases:\n\n# contributed by Gunnar Hjalmarsson\nuse Time::Local;\nmy $today = timelocal 0, 0, 12, ( localtime )[3..5];\nmy ($d, $m, $y) = ( localtime $today-86400 )[3..5]; # WRONG\nprintf \"Yesterday: %d-%02d-%02d\\n\", $y+1900, $m+1, $d;\n\nHow do I validate input?\n(contributed by brian d foy)\n\nThere are many ways to ensure that values are what you expect or want to\naccept. Besides the specific examples that we cover in the perlfaq, you\ncan also look at the modules with \"Assert\" and \"Validate\" in their\nnames, along with other modules such as Regexp::Common.\n\nSome modules have validation for particular types of input, such as\nBusiness::ISBN, Business::CreditCard, Email::Valid, and\nData::Validate::IP.\n",
                "subsections": []
            },
            "Found in /usr/share/perl/5.34/pod/perlfaq5.pod": {
                "content": "How do I randomly update a binary file?\nIf you're just trying to patch a binary, in many cases something as\nsimple as this works:\n\nperl -i -pe 's{window manager}{window mangler}g' /usr/bin/emacs\n\nHowever, if you have fixed sized records, then you might do something\nmore like this:\n\nmy $RECSIZE = 220; # size of record, in bytes\nmy $recno   = 37;  # which record to update\nopen my $fh, '+<', 'somewhere' or die \"can't update somewhere: $!\";\nseek $fh, $recno * $RECSIZE, 0;\nread $fh, $record, $RECSIZE == $RECSIZE or die \"can't read record $recno: $!\";\n# munge the record\nseek $fh, -$RECSIZE, 1;\nprint $fh $record;\nclose $fh;\n\nLocking and error checking are left as an exercise for the reader. Don't\nforget them or you'll be quite sorry.\n",
                "subsections": []
            },
            "Found in /usr/share/perl/5.34/pod/perlfaq8.pod": {
                "content": "How do I set the time and date?\nAssuming you're running under sufficient permissions, you should be able\nto set the system-wide date and time by running the date(1) program.\n(There is no way to set the time and date on a per-process basis.) This\nmechanism will work for Unix, MS-DOS, Windows, and NT; the VMS\nequivalent is \"set time\".\n\nHowever, if all you want to do is change your time zone, you can\nprobably get away with setting an environment variable:\n\n$ENV{TZ} = \"MST7MDT\";           # Unixish\n$ENV{'SYS$TIMEZONEDIFFERENTIAL'}=\"-5\" # vms\nsystem('trn', 'comp.lang.perl.misc');\n",
                "subsections": []
            }
        }
    }
}