Skip to content

Instantly share code, notes, and snippets.

@tofl
Last active December 21, 2015 00:19
Show Gist options
  • Save tofl/6219530 to your computer and use it in GitHub Desktop.
Save tofl/6219530 to your computer and use it in GitHub Desktop.
A simple "date translator"...
<?php
function date_translate($day, $month, $year, $text) {
// day
if ($day == '01') {
$day = '1';
} elseif ($day == '02') {
$day = '2';
} elseif ($day == '03') {
$day = '3';
} elseif ($day == '04') {
$day = '4';
} elseif ($day == '05') {
$day = '5';
} elseif ($day == '06') {
$day = '6';
} elseif ($day == '07') {
$day = '7';
} elseif ($day == '08') {
$day = '8';
} elseif ($day == '09') {
$day = '9';
}
// suffix
if ($day == '01' OR $day == '1' OR $day == '21' OR $day == '31') {
$suff = 'st';
} elseif ($day == '02' OR $day == '2' OR $day == '22') {
$suff = 'nd';
} elseif ($day == '03' OR $day == '3' OR $day == '23') {
$suff = 'rd';
} else {
$suff = 'th';
}
// month
if ($month == '01' OR $month == '1') {
$month = 'January';
} elseif ($month == '02' OR $month == '2') {
$month = 'February';
} elseif ($month == '03' OR $month == '3') {
$month = 'March';
} elseif ($month == '04' OR $month == '4') {
$month = 'April';
} elseif ($month == '05' OR $month == '5') {
$month = 'May';
} elseif ($month == '06' OR $month == '6') {
$month = 'June';
} elseif ($month == '07' OR $month == '7') {
$month = 'July';
} elseif ($month == '08' OR $month == '8') {
$month = 'August';
} elseif ($month == '09' OR $month == '9') {
$month = 'September';
} elseif ($month == '10') {
$month = 'October';
} elseif ($month == '11') {
$month = 'November';
} elseif ($month == '12') {
$month = 'December';
}
echo $text . ' ' . $month . ' the ' . $day . '<sup>' . $suff . '</sup>, ' . $year;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment