Jump to content

[SOLVED] Help with PHP date


DBookatay

Recommended Posts

Well there are quite a few:

 

#1

$time = strtotime($row['date']); print date('r', $time);

 

#2

list($year, $month, $day) = explode('-', $row['date']); print date('r', mktime(0, 0, 0, $month, $day, $year));

 

Ok, thanks.

This is how I had it:

$month = substr($row['date'], 5, 2);
switch($month){
case '01': $month = 'January'; break;
case '02': $month = 'Febuary'; break;
case '03': $month = 'March'; break;
case '04': $month = 'April'; break;
case '05': $month = 'May'; break;
case '06': $month = 'June'; break;
case '07': $month = 'July'; break;
case '08': $month = 'August'; break;
case '09': $month = 'September'; break;
case '10': $month = 'October'; break;
case '11': $month = 'November'; break;
case '12': $month = 'December'; break;
}
$day = substr($row['date'], 8, 2);
switch($day){
case '01': $day = '1st'; break;
case '02': $day = '2nd'; break;
case '03': $day = '3rd'; break;
case '04': $day = '4th'; break;
case '05': $day = '5th'; break;
case '06': $day = '6th'; break;
case '07': $day = '7th'; break;
case '08': $day = '8th'; break;
case '09': $day = '9th'; break;
case '10': $day = '10th'; break;
case '11': $day = '11th'; break;
case '12': $day = '12th'; break;
case '13': $day = '13th'; break;
case '14': $day = '14th'; break;
case '15': $day = '15th'; break;
case '16': $day = '16th'; break;
case '17': $day = '17th'; break;
case '18': $day = '18th'; break;
case '19': $day = '19th'; break;
case '20': $day = '20th'; break;
case '21': $day = '21st'; break;
case '22': $day = '22nd'; break;
case '23': $day = '23rd'; break;
case '24': $day = '24th'; break;
case '25': $day = '25th'; break;
case '26': $day = '26th'; break;
case '27': $day = '27th'; break;
case '28': $day = '28th'; break;
case '29': $day = '29th'; break;
case '30': $day = '30th'; break;
}
$year = substr($row['date'], 0, 4);
$date = $month.' '.$day.', '.$year;


but figured there had to be an easier way of doing it...

Yes as suggested by dan. First convert the date from your database to unix timestamp using strtotime

$time = strtotime($row['date']);

 

Now using the date (click that link for documentation) function you can format the date how you like. example

$time = strtotime($row['date']);
echo date('D jS M Y', $time);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.