{
    "mode": "perldoc",
    "parameter": "Date::Manip::Examples",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Date%3A%3AManip%3A%3AExamples/json",
    "generated": "2026-06-17T05:07:53Z",
    "sections": {
        "NAME": {
            "content": "Date::Manip::Examples - examples of how to use Date::Manip\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This document includes a number of examples on how to do common Date::Manip operations. I will\nbe happy to add new examples over time, and welcome suggestions and examples to include.\n\nIn most cases, an example will include two different ways of getting the answer. The first way\nwill be using the new (as of 6.00) OO modules. The second will be using the old-style functional\ninterface.\n\nIt should be noted that any time you want to work with alternate time zones, the OO interface is\nSTRONGLY recommended since the functional interface does not preserve time zone information with\nthe date, and may therefore give incorrect results in some cases. However, working in the time\nzone of the system should give correct results.\n\nIt should be noted that, in the examples below, it appears that the OO method often requires\nmore lines of code than the functional interface. There are a number of ways to shorten the OO\nmethod, but for the examples, I wanted to include all the steps explicitly.\n",
            "subsections": []
        },
        "PARSING A DATE": {
            "content": "Dates can be parsed in practically any form in common usage:\n\nOO method\n$date = new Date::Manip::Date;\n$err = $date->parse(\"today\");\n$err = $date->parse(\"1st Thursday in June 1992\");\n$err = $date->parse(\"05/10/93\");\n$err = $date->parse(\"12:30 Dec 12th 1880\");\n$err = $date->parse(\"8:00pm December tenth\");\n\nFunctional\n$date = ParseDate(\"today\");\n$date = ParseDate(\"1st Thursday in June 1992\");\n$date = ParseDate(\"05/10/93\");\n$date = ParseDate(\"12:30 Dec 12th 1880\");\n$date = ParseDate(\"8:00pm December tenth\");\n\nThe Date::Manip::Date manual has a list of all valid formats.\n",
            "subsections": []
        },
        "PARSING AN AMOUNT OF TIME": {
            "content": "Amounts of time (referred to as deltas) can also be parsed:\n\nOO method\n$delta = new Date::Manip::Delta;\n$err = $delta->parse(\"in 12 hours\");\n$err = $delta->parse(\"-1:30:0\");\n$err = $delta->parse(\"4 business days later\");\n\nFunctional\n$delta = ParseDateDelta(\"in 12 hours\");\n$delta = ParseDateDelta(\"-1:30:0\");\n$delta = ParseDateDelta(\"4 business days later\");\n",
            "subsections": []
        },
        "TO CALCULATE THE AMOUNT OF TIME BETWEEN TWO DATES": {
            "content": "$datestr1 = \"Jan 30 1999 13:00 EST\";\n$datestr2 = \"2/Mar/1999 15:30:00 +0500\";\n\nOO method\n$date1 = new Date::Manip::Date;\n$date2 = $date1->newdate();\n$err = $date1->parse($datestr1);\n$err = $date2->parse($datestr2);\n\nTo get an exact amount of time between the two dates (expressed only in terms of hours,\nminutes, seconds), use:\n\n$delta = $date1->calc($date2);\n\nTo get an approximate amount of time (expressed in terms of years, months, weeks, etc. in\nterms that a human would typically think of), use:\n\n$delta = $date1->calc($date2,\"approx\");\n\nFunctional\n$date1 = ParseDate($string1);\n$date2 = ParseDate($string2);\n\nTo get an exact amount:\n\n$delta = DateCalc($date1,$date2);\n\nand the approximate amount:\n\n$delta = DateCalc($date1,$date2,1);\n\nThe Date::Manip::Calc manual has information about these, and other types of calculations.\n",
            "subsections": []
        },
        "TO ADD AN AMOUNT OF TIME TO A DATE": {
            "content": "To find a second date a given amount of time before or after a first date, use the following:\n\n$datestr  = \"Jan 30 1999 13:00 EST\";\n$deltastr = \"12 hours ago\";\n$deltastr = \"in 3 business days\";\n\nOO method\n$date = new Date::Manip::Date;\n$delta = $date->newdelta();\n$date->parse($datestr);\n$delta->parse($deltastr);\n\n$d = $date->calc($delta);\n\nFunctional\n$date = DateCalc($datestr,$deltastr);\n\nIf the delta is a business delta, it will do a business mode calculation.\n\nThe Date::Manip::Calc manual has information about these, and other types of calculations.\n",
            "subsections": []
        },
        "COMPARE TWO DATES": {
            "content": "To take two different dates and see which is earlier, do the following:\n\n$datestr1 = \"Jan 30 1999 13:00 EST\";\n$datestr2 = \"2/Mar/1999 15:30:00 +0500\";\n\nOO method\n$date1 = new Date::Manip::Date;\n$date2 = $date1->newdate;\n$date1->parse($datestr1);\n$date2->parse($datestr2);\n\n$date1->cmp($date2);\n=> -1, 0, 1\n\nFunctional\n$date1 = ParseDate($datestr1);\n$date2 = ParseDate($datestr2);\n\nDateCmp($date1,$date2);\n=> -1, 0, 1\n",
            "subsections": []
        },
        "TO EXTRACT INFORMATION ABOUT A DATE OR DELTA": {
            "content": "If you have a date or a delta, you can extract information about them as follows:\n\n$datestr  = \"1:24:08 PM EST Feb 3, 1996\";\n$deltastr = \"12 hours ago\";\n\nOO method\n$date = new Date::Manip::Date;\n$delta = $date->newdelta();\n$date->parse($datestr);\n$delta->parse($deltastr);\n\n$str = $date->printf(\"It is now %T on %b %e, %Y.\");\n=>  \"It is now 13:24:08 on Feb  3, 1996.\"\n\n$str = $delta->printf(\"In %hv hours, %mv minutes, %sv seconds\");\n=> \"In -12 hours, 0 minutes, 0 seconds\";\n\nFunctional\n$str = UnixDate($datestr,\"It is now %T on %b %e, %Y.\");\n=>  \"It is now 13:24:08 on Feb  3, 1996.\"\n\n$str = DeltaFormat($deltastr,\"In %hv hours, %mv minutes, %sv seconds\");\n=> \"In -12 hours, 0 minutes, 0 seconds\";\n\nThe Date::Manip::Date manual contains all of the format codes that can be used to extract\ninformation from a date. The Date::Manip::Delta manual contains the codes for a delta.\n",
            "subsections": []
        },
        "WORKING WITH EPOCH": {
            "content": "Date::Manip can easily be used to work with the number of seconds since the epoch (Jan 1, 1970\n00:00:00 UTC).\n\nIf you have a date, and you want to find out how many seconds it is after the epoch, you can do\nit in the following ways:\n\n$datestr  = \"1999-04-30-15:30:00 EDT\";\n$secs  = 1234567;\n\nOO method\nTo find out how many seconds have elapsed on a certain date, you can do the following:\n\n$date     = new Date::Manip::Date;\n$err      = $date->parse($datestr);\n\n$str      = $date->printf('%s');\n=> number of seconds\n\nTo find out the date that is a certain number of seconds since the epoch, you can use the\nfollowing:\n\n$date  = new Date::Manip::Date;\n$err   = $date->parse(\"epoch $secs\");\n\n$date now contains the date wanted (in the local time zone)\n\nFunctional\nTo find out how many seconds have elapsed:\n\n$str = UnixDate($datestr,'%s');\n=> number of seconds\n\nTo find the date that is a number of seconds since the epoch:\n\n$date = ParseDateString(\"epoch $secs\");\n\nNote that Date::Manip will work with both positive seconds (for dates that have come since the\nepoch) and negative seconds (for dates that occurred before the epoch).\n",
            "subsections": []
        },
        "RECURRING EVENTS": {
            "content": "To find a list of dates where a recurring event happens (even very complex recurrences), do the\nfollowing:\n\nOO method\n# To find the 2nd Tuesday of every month from Jan 1 1999 to Apr 30 1999\n\n$recur = new Date::Manip::Recur;\n$start = $recur->newdate();\n$end   = $recur->newdate();\n$start->parse(\"Jan 1 1999\");\n$end->parse(\"Apr 30 1999\");\n\n$recur->parse(\"0:1*2:2:0:0:0\",$start,$end);\n@date = $recur->dates();\n\n# To find the Monday after Easter in 1997-1999\n\n$recur = new Date::Manip::Recur;\n$recur->parse(\"*1997-1999:0:0:0:0:0:0*EASTER,ND1\");\n@date = $recur->dates();\n\nFunctional\n# To find the 2nd Tuesday of every month from Jan 1 1999 to Apr 30 1999\n@date = ParseRecur(\"0:1*2:2:0:0:0\",\"\",\"Jan 1 1999\",\"Apr 30 1999\");\n\n# To find the Monday after Easter in 1997-1999.\n@date = ParseRecur(\"*1997-1999:0:0:0:0:0:0*EASTER,ND1\");\n\nThe Date::Manip::Recur manual contains information about recurring events.\n",
            "subsections": []
        },
        "WORKING WITH DATES IN ANOTHER LANGUAGE": {
            "content": "If you want to work with dates in a language other than English (but you are only working with a\nsingle language), do the following:\n\nOO method\n$date = new Date::Manip::Date;\n$date->config(\"Language\",\"French\",\"DateFormat\",\"non-US\");\n$date->parse(\"1er decembre 1990\");\n\nFunctional\nDateInit(\"Language=French\",\"DateFormat=non-US\");\n$date = ParseDate(\"1er decembre 1990\");\n\nThe Date::Manip::Config manual has a list of all supported languages (in the section on the\nLanguage config variable). The meaning of the DateFormat config variable is also included.\n",
            "subsections": []
        },
        "WORKING WITH TWO DIFFERENT LANGUAGES": {
            "content": "If you want to work with dates in two (or more) languages, it is STRONGLY recommended that you\nuse the OO interface. The functional interface will be much slower since it has to re-initialize\na lot of language-specific stuff every time you switch back and forth between languages.\n\nOO method\n$dateeng = new Date::Manip::Date;\n$dateeng->config(\"Language\",\"English\",\"DateFormat\",\"US\");\n\n$datefre = new Date::Manip::Date;\n$datefre->config(\"Language\",\"French\",\"DateFormat\",\"non-US\");\n\nUse the $dateeng object to do English operations, the $datefre object to do French\noperations.\n\nFunctional\nIf you are working with both French and English dates, you can call the following to switch\nbetween them:\n\nDateInit(\"Language=French\",\"DateFormat=non-US\");\nDateInit(\"Language=English\",\"DateFormat=US\");\n\nThis is NOT recommended. Use the OO method instead.\n",
            "subsections": []
        },
        "BUGS AND QUESTIONS": {
            "content": "Please refer to the Date::Manip::Problems documentation for information on submitting bug\nreports or questions to the author.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Date::Manip - main module documentation\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This script is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Sullivan Beck (sbeck@cpan.org)\n",
            "subsections": []
        }
    },
    "summary": "Date::Manip::Examples - examples of how to use Date::Manip",
    "flags": [],
    "examples": [],
    "see_also": []
}