days left in the month hack
-
I have a particular task that I have to do once a month, every month. A friend of mine created a hack for me that reminds me of the task and how many days are left in the month to perform the task. This hack also accounts for leap years. I figured out that the way it was coded was removing the names of the months from the dates that appeared above my posts (so that the dates were appearing as “1 2004 (Saturday)” instead of as “1 July 2004 (Saturday). My friend adjusted the code a little bit for me so that now it works better. Here is the code that I place in the my-hacks.php file. The call that needs to be placed in the index.php file is farther below.
<?php
$today = date( “j” );
$ht_month = date( “n” );
if ( $ht_month == 4 || $ht_month == 6 || $ht_month == 9 || $ht_month == 11 )
{
$max = 30;
}
else if ( $ht_month == 2 )
{
$max = ( date( “L” ) == 1 ) ? 29 : 28;
}
else
{
$max = 31;
}
$left = ( $max – $today );
$left = ( $left == 1 ) ? “is $left day” : “are $left days”;
?>
The call (placed in index.php wherever you want it to show up, with whatever reminder message you wanted):
There <?php print $left; ?> left to earn next month’s rent.
- The topic ‘days left in the month hack’ is closed to new replies.