>>>>> "M" == Matt <lm7...@gmail.com> writes:
M> Have a date: M> 2011-05-02-16:40:51 M> Using this to get it: M> $tm = gmtime; M> $time_stamp = sprintf "%04d-%02d-%02d-%02d:%02d:%02d", M> $tm->year + 1900, $tm->mon + 1, $tm->mday, $tm->hour, $tm->min, $tm->sec; M> print "$time_stamp\n"; use POSIX strftime for that. i have seen experienced hacker code not using that call. it provides dozens of time format outputs including all the common ones and several groups of them too. same format as the date unix command (which just wraps this call). M> I need to round it to nearest 5 minute point. M> 2011-05-02-16:40:51 M> needs rounded like so. M> 2011-05-02-16:00:00 M> 2011-05-02-16:45:00 M> 2011-05-02-16:50:00 M> 2011-05-02-16:55:00 M> My thought is a bunch of if statements but that seems ugly. Is there M> a better/easier way? just zero out the seconds and do a simple round operation on the minutes. you can use sprintf for the rounding (many examples in the list archives). and you can still use strftime. just put gmtime into an array (no reason to use 9 vars), zero out the seconds slot, round the minutes slot, pass the array to strftime. uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/