Contact Us

Scripts: Perl :: Date and Time :: Library Article #5

Developer's Section

Computing the Current Date and extracting its individual values in Perl
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (3345)

This article describes how to compute the current date in Perl and teaches you how to extract its individual values.

In is very easy to extract common values from a Date Object into an array such as the year, month, day, hour, minutes, and seconds. All this requires is declaring the array with the individual variables passed from the function call localtime(time).


 Code Snippet 1

#!/usr/bin/perl -w

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

use Time::Local;

print "Content-type: text/plain\n\n";

#declare array returned from localtime

#print the date using newly extracted values
printf "%4d-%02d-%02d %02d:%02d:%02d\n", $year+1900,$mon+1,$mday,$hour,$min,$sec;

#calculate system time again from the extracted values
my $time2 = timelocal($sec,$min,$hour,$mday,$mon,$year);

#calculate the difference (in seconds) of two system times
$difference = time - $time2;

exit 0; 

See other Scripts in Date and Time

Submit Your Scripts:

If you would like to have your Perl scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]