Hi,
I was wanting to write some code to work out whether I needed st, nd rd or
th in my dates.
While the code below works, I am certain that there is a better way....
if (($daterep == "1") || ($daterep == "21") || ($daterep == "31")){
$letters = "st";
} elseif (($daterep == "2") || ($daterep == "22")){
$letters = "nd";
} elseif (($daterep == "3") || ($daterep == "23")){
$letters = "rd";
} else {
$letters = "th";
}
I tried:
if ($daterep == "1" || "21" || "31") { ... etc
but it did not work... I don't understand why though?
I cast $daterep into a string, but now I find that I could have left it
alone....
Any suggestions as to how to get this code working a bit smoother?
Robert
I was wanting to write some code to work out whether I needed st, nd rd or
th in my dates.
While the code below works, I am certain that there is a better way....
if (($daterep == "1") || ($daterep == "21") || ($daterep == "31")){
$letters = "st";
} elseif (($daterep == "2") || ($daterep == "22")){
$letters = "nd";
} elseif (($daterep == "3") || ($daterep == "23")){
$letters = "rd";
} else {
$letters = "th";
}
I tried:
if ($daterep == "1" || "21" || "31") { ... etc
but it did not work... I don't understand why though?
I cast $daterep into a string, but now I find that I could have left it
alone....
Any suggestions as to how to get this code working a bit smoother?
Robert
Comment