Re: Convert string into incremental date
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 30 May 2006 13:07:29 -0700
djray wrote:
My question is two part:
1. I am reading a date from a file in the form mm/dd/yy (i.e.
05/30/06). I need to convert that string into a date.
2. I need to be able to increment that date:
Example:
$date = 05/30/06;
$date = $date + 1; ($date = 05/31/06)
$date = $date + 1; ($date = 06/01/06)
Any help would be greatly appreciated.
There are probably 10 different modules on CPAN that can help you with
this. Have you looked there yet? http://search.cpan.org search for
"date" and/or "time".
If your data really is that structured, however, you might not need to
bother with a CPAN module. Parse out the three numbers using a regular
expression (see perldoc perlre), convert them to seconds since the
epoch using Time::Local's timelocal() (see perldoc Time::Local), and
add one day (24 * 60 * 60), and convert to a string of your choosing
using POSIX's strftime (see `man strftime`) and localtime() (see
perldoc -f localtime).
(standard warnings about daylight savings time apply...)
Hope this helps,
Paul Lalli
.
- References:
- Convert string into incremental date
- From: djray
- Convert string into incremental date
- Prev by Date: Re: Convert string into incremental date
- Next by Date: Re: better idiom for appending to list from file
- Previous by thread: Re: Convert string into incremental date
- Next by thread: Re: Convert string into incremental date
- Index(es):
Relevant Pages
|
|