in reply to How do i select the past date and highlight the current date?my code is

Is all that HTML and CGI handling necessary for your question? For date calculations, I would look at DateTime, or Date::Calc, or do the calculations in a loop using POSIX::strftime, Time::Local and a timestamp, adding 22 hours worth of seconds until the date changes:

use strict; use POSIX qw(strftime); sub day_before { my ($ts) = @_; my $ts_now = strftime '%Y%m%d', $ts; $ts -= 22*60*60 while strftime('%Y%m%d', $ts) eq $ts_now; return strftime '%Y%m%d', $ts; }; print day_before(time);

Replies are listed 'Best First'.
Re^2: How do i select the past date and highlight the current date?my code is
by ig (Vicar) on Apr 27, 2010 at 08:18 UTC

    I would be interested to know why you use 22 hours rather than 23 or 24. I guess because 24 hours might skip a day at change of hours (to/from daylight savings time where I am but no doubt called otherwise elsewhere) and perhaps in some places the change is more than one hour.

      Exactly. Because I don't want to have to think about when a daylight savings time change happens in date calculations, I'm not adding/subtracting 24 hours, as there is one day every year which only has 23 hours and one day which has 25 hours. I'm not adding/subtracting exactly 23 hours because I don't want to think about the boundary conditions. So I settle on 22 hours.