Few days ago I was programing for a customer that asked to show entered data from a database fom today up to 7 days ago.
Simples task, huh?
I found no resorce with a routine to help me out nor intend to use a hole module just for that, then I come up with this stupid and simple solution that I what to share:
# copyright Gilnei Moraes <gm199@fenomeno.com>
for ($i = 0; $i <= 6; $i++) { # 6 is the desired days
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - (86400*$i)); #86400 is the total seconds in a day
$mday = "0$mday" if ($mday < 10);
$hour = "0$hour" if ($hour < 10);
$min = "0$min" if ($min < 10);
$month = ++$mon;
$month = "0$month" if ($month < 10);
$year = 1900 + $year;
#$count = "$mday-$hour-$min";
$count = "$mday/$month/$year";
print "$count<br>\n";
}
Simples task, huh?
I found no resorce with a routine to help me out nor intend to use a hole module just for that, then I come up with this stupid and simple solution that I what to share:
# copyright Gilnei Moraes <gm199@fenomeno.com>
for ($i = 0; $i <= 6; $i++) { # 6 is the desired days
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - (86400*$i)); #86400 is the total seconds in a day
$mday = "0$mday" if ($mday < 10);
$hour = "0$hour" if ($hour < 10);
$min = "0$min" if ($min < 10);
$month = ++$mon;
$month = "0$month" if ($month < 10);
$year = 1900 + $year;
#$count = "$mday-$hour-$min";
$count = "$mday/$month/$year";
print "$count<br>\n";
}