in reply to changing a string to a useable date time
You are going to need to define what you mean since it already appears to be in the first format. Likely, you probably want to use Time::Local, and then use strftime from POSIX to format however you want. Both modules are part of the core.
Incidently, $epoch is number of seconds since epoch so it is easy to calculate the difference between two stamps just by subtracting and dividing by the appropriate number of seconds (86_400 if you want the difference in days).#!/usr/bin/perl use strict; use warnings; use Time::Local; use POSIX 'strftime'; my $str = '19980730010031'; my $epoch = get_epoch( $str ); print strftime("%m/%d/%Y", localtime($epoch)); sub get_epoch { my $str = shift; my ($yr, $mon, $day, $hr, $min, $sec) = unpack('A4A2A2A2A2A2', $st +r); $mon--; return timelocal($sec, $min, $hr, $day, $mon, $yr); }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: changing a string to a useable date time
by cpiety (Novice) on Feb 01, 2005 at 16:28 UTC | |
by Limbic~Region (Chancellor) on Feb 01, 2005 at 16:31 UTC | |
by cpiety (Novice) on Feb 01, 2005 at 16:49 UTC |