It's not April 20, it's the 20th
A tutorial on how to properly date a time. If you've ever fetched the date in any programming language it usually comes out plain :(, example: April 20. Usually we'd like to see April 20th. So here's a quick function in php to do that.
function pdate($proper) {
if(substr(date('j', $proper), -1) == "1") {
$th = "st";
}
elseif(substr(date('j', $proper), -1) == "2") {
$th = "nd";
}
elseif(substr(date('j', $proper), -1) == "3") {
$th = "rd";
}else{
$th = "th";
}
print($th);
}
What that does is create a st, nd, rd, or th based off the current date. So here's an actual code that you may come across:
<?php
$time = time();
echo date('F j', $time); // This will return MONTH DAY (for example April 20)
//Now let's add the ending
echo pdate($time);
?>
Our final result: April 20th. You may want to stylize the ending by superscripting it. Just modify the pdate(); with this:
<?php
//Now let's add the ending
echo " < sup >";
echo pdate($time);
echo "< /sup >";
?>
jonathan
April 20 2010
Very interesting, love looking at php code, some ugly stuff!
But why doesnt TTI do that, when you can see when something is posted it is April 20! ?