Re: Convert string into incremental date



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

.



Relevant Pages

  • Re: current date
    ... > Yes, use timeto fetch the current time, localtime() to break ... > it down into a struct tm, then extract the structure members of that ... That's what strftime is for. ...
    (comp.lang.c)
  • Re: localtime(time())
    ... print strftime '%Y-%m-%d', localtime; ... I'm not sure that using POSIX is simpler, since at least I would need ... localtime, that you have to add ... beginner level Perl programmers. ...
    (comp.lang.perl.misc)
  • Re: localtime(time())
    ... print strftime '%Y-%m-%d', localtime; ... I'm not sure that using POSIX is simpler, since at least I would need to look up the applicable conversion specifiers. ... Working with localtime() and printfis simple enough even for beginner level Perl programmers. ...
    (comp.lang.perl.misc)
  • Re: Filnames and timestamps
    ... hints or advice would be appreciated;-) ... The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html The C-library: http://www.dinkumware.com/refxc.html ...
    (comp.lang.c)