This subroutine takes most of the guess out of working with dates in Perl
programs. This program, after being called returns a few useful time/date
options but is VERY EASY TO RECONFIGURE! Below are the instructions on how
to use the script and a list of what is returned. You can, with a little
fiddling, create any date combo you want!
Bonus: How many times have you wanted to generate a unique ID
number in your program? Instead of fiddling with rand() and
srand(), this script/subroutine returns a unique number that the
odds of being duplicated are insanely high. It returns an eighteen digit
unique number based on the date an process id of the execution of the
program calling the script!
To use the sub/script:
At any point in your script before you call it, you must "require" the script
so that it may be accessible to your program. This is done by the following
After that you just call the script before attempting to parse any form data:
(NOTE: In the subroutine script there is a place for you to set an offset
if you are not in the same timezone as your server.)
Other variables from the subroutine you can use:
- $DATE returns Date in the format "yyyy/mm/dd".
- $TIME returns Time in the format "hh:mm:ss".
- $PID_DATE Unique number in the format "nnnnnnnnnnnnnnnnnn";
- $MONTH returns Month (number)
- $THISYEAR returns Year
- $DAYOFMONTH returns Day of Month (number)
(NOTE: This script is easy to re-write to generate word values for
the month and day of week. Consider it a test!)