Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date/Time Manipulation

Status
Not open for further replies.

SOL9MAN

Technical User
Mar 11, 2003
12
0
0
GB
I need to add a number of minutes to a variable which stores a datetime stamp in the following format DDMMYYYY HH:MM:SS. Currently I am converting the time into a julian time, add the number of minutes(see below). However this method only works if a day has 24 hours. During Daylight saving a day could have either 23 or 25 hours. Therefore this will not work. What is the best way to get round this.


my $julian_time = timelocal(substr(@ARGV[0],15,2),substr(@ARGV[0],12,2),substr(@ARGV[0],9,2),substr(@ARGV[0],6,2),substr(@ARGV[0],4,2)-1,substr(@ARGV[0],0,4))
;
$julian_time+=(@ARGV[1]*60);
my @tmstmp = localtime($julian_time);
 
Hi there,

Perl dates, like UNIX dates, are the number of seconds since a date in 1970 (I think, doesn't matter)

Easiest way to deal with Perl dates is to let Perl worry about Daylight saving etc.

Store dates as Perl dates, use arithmatic to add and subtract seconds, and then use functions like localtime() and gmtime() to convert to formats easier for us to read.

Mike

"Deliver me from that bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
I use the DateManip module for most of my date and time handling. Check it out, it might help.


Michael Libeson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top