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
In reply to Re: changing a string to a useable date time
by Limbic~Region
in thread changing a string to a useable date time
by cpiety
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |