DBookatay Posted July 19, 2009 Share Posted July 19, 2009 How do I convert the value of date row "2007-05-19", it something that displays like: May 19th, 2007? I've tried every possible scenerio that I can think of with no luck... Link to comment https://forums.phpfreaks.com/topic/166513-solved-help-with-php-date/ Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Use strtotime to make it a UNIX timestamp. Then use date to format that. Link to comment https://forums.phpfreaks.com/topic/166513-solved-help-with-php-date/#findComment-878099 Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 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)); Link to comment https://forums.phpfreaks.com/topic/166513-solved-help-with-php-date/#findComment-878100 Share on other sites More sharing options...
DBookatay Posted July 19, 2009 Author Share Posted July 19, 2009 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... Link to comment https://forums.phpfreaks.com/topic/166513-solved-help-with-php-date/#findComment-878102 Share on other sites More sharing options...
wildteen88 Posted July 19, 2009 Share Posted July 19, 2009 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); Link to comment https://forums.phpfreaks.com/topic/166513-solved-help-with-php-date/#findComment-878107 Share on other sites More sharing options...
DBookatay Posted July 19, 2009 Author Share Posted July 19, 2009 Thank you! Link to comment https://forums.phpfreaks.com/topic/166513-solved-help-with-php-date/#findComment-878117 Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 It started out as a simple site, 3 years later it just gets more and more complex: http://www.carcityofdanbury.com A website is like raising a child. Cute at first but as it grows older, so do your worries Link to comment https://forums.phpfreaks.com/topic/166513-solved-help-with-php-date/#findComment-878265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.