On Aug 17, Pablo Fischer said:

>030817145

Does that represent...

  03 -> 2003
  08 -> August
  17 -> 17th
  14 -> 2pm
  5  -> 5 minutes

I'm a little wary of that form of storing the date, but I suppose we can
deal with it.

>However in some parts of my code I need to get another date, and I only have:
>030817145 and that I need the time in 10 minutes before/after, how can I
>calculate this?.
>
>For example If I add 5 minutes to 030817145, I need to get:
>Sun Aug 17 14:10:21 2003

You'll FIRST need to convert your "time" format to one that you can get
the current number of seconds since 1970 out of.

  use Time::Local;
  my $time = "030817145";
  my ($year, $mon, $day, $hr, $min) = unpack "A2 A2 A2 A2 A2 A*", $time;
  my $seconds = timelocal(0, $min, $hr, $day, $mon - 1, $year + 100);

If you're curious, I'm subtracting one from $mon because Perl starts
months at zero, and adding 100 to $year because Perl subtracts 1900 from
the year, so 2003 is 103 to Perl.

Now, we just add the number of seconds in 5 minutes to $seconds, and use
localtime() to get back the new date:

  my $MINUTES = 5;
  my $date_string = localtime($seconds + 60 * $MINUTES);

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to