Thursday, 12 September 2013

Subtracting date by one and obey calendar correctly

Subtracting date by one and obey calendar correctly

Im attempting to subtract the day by one with localtime, but I also need
it to obey the monthly format.
For example, let's say it's July first, my program will need to display
data from June 30th with localtime, but if I subtract the date by 1 it's
not going to be helpful.
my $minutes_back = 4;
my $dt = localtime( time - $minutes_back * 60 );
my $date_from=sprintf("%d/%d/%d",$dt->mon,$dt->mday,$dt->year);
Does anyone have a better way, other than me storing the current date and
doing an eval if it's the first then backtrack to the previous month?

No comments:

Post a Comment