Perl Date::Manip on Windows
Tuesday, September 11th, 2007 at 9:56 am
Date::Manip doesn’t work “straight out of the box” on Windows due to the fact that Windows doesn’t have a timezone defined. I use Perl on both Unix and Windows and as a result I use Date::Manip on both systems as well. When I was a newbie this confounded me to no end when coding for Windows. I couldn’t seem to find a good solution for it but ultimately through research and determination I figured out how to fix it.
I create a system variable in Windows for the timezone and then modify the Perl module to use this system variable. This way I don’t have to make changes in all my scripts, I just make the change once on the system and then code normally with Date::Manip. Here are the step-by-step instructions:
Open the following Perl Module in your favorite text editor: C:\Perl\site\lib\Date\Manip.pm
(Remove read only restriction temporarily beforehand.) This assumes your Perl installation is in the default location.
Around line 105 you’ll see a comment: #Local timezone
Change the code below it as follows:
$Cnf{"TZ"}="";
now becomes
$Cnf{"TZ"}=$ENV{'TZ'};
Save the file, set back to read only.
Now create the environment variable:
- Right Click on “My Computer”, Click “Properties”
- Click the “Advanced” tab
- Click the “Environment Variables” button
- Click the “New” button under “System variables”
- Enter ‘TZ’ for the Variable name (without the quotes)
- Enter ‘CST6CDT’ for the Variable value (without the quotes) This is central standard daylight savings time. You’ll have to lookup your own timezone abbreviation if you live outside the Central zone.
- Click “OK”
- Click “OK” again
- Click “OK” again
If you have any DOS windows open close them and reopen them (so they’ll import your new environment variable). Now you should be able to code for Date::Manip just as you would on Unix or Linux.
I’ve also read about another method of just setting the time zone in the program itself as so:
Date_Init("TZ=CDT");
I haven’t personally tested it but I decided to include it as an alternative. You would have to set this in all your programs using Date::Manip so I prefer doing it at a system level.
FACT: Chuck Norris successfully seperated twins conjoined at the head by roundkicking them in the face.

Leave a Reply