Wednesday
Nov102004
A Gem For You
Wednesday, November 10, 2004 at 10:28AM
While spelunking in the depths of some code at work today, Jaxn found a little gem left by the previous explorers:
The only justification I have for this abomination is a situation where the boxes times are not synchronized. This method would force all machines to be synced from the time on the database server, but, cmon, we have ways of doing that.
For those of you playing along at home, the much less expensive method is:
I would use DateTime rather than
UPDATE:
I found a similar line while I was doing my latrine duty:
The more educated among you may recognize this as a reimplemention of
($day) = $dbh->selectrow_array("SELECT DATE_SUB(NOW(), INTERVAL 1 DAY)");
($day) = split(/s/, $day);
The only justification I have for this abomination is a situation where the boxes times are not synchronized. This method would force all machines to be synced from the time on the database server, but, cmon, we have ways of doing that.
For those of you playing along at home, the much less expensive method is:
@date = localtime(time() - 86400);
$date = sprintf("%d-%02d-%02d", $date[5] + 1900, $date[4] + 1, $date[3]);
I would use DateTime rather than
time() or localtime().UPDATE:
I found a similar line while I was doing my latrine duty:
my ($time) = $dbh->selectrow_array("SELECT NOW()");
$time = str_to_unixtime($time);
The more educated among you may recognize this as a reimplemention of
time().

Reader Comments (1)
Code Snippet of the Week
# If we don't get a day , then use today's date.
#
if ( !$day ) {
($day) = $dbh->selectrow_array("SELECT DATE_SUB(NOW(), INTERVAL 1 DAY)");
($day) = split(/\s/, $day);
}
It is getting yesterday's date from the database instead of jus...