Woodburn2006 Posted September 11, 2007 Share Posted September 11, 2007 if i have a date stored in my DB as 11/09/2007 is there anyway i can change it to 11th Sep once i have pulled it from the DB? Link to comment https://forums.phpfreaks.com/topic/68906-date-format/ Share on other sites More sharing options...
Jessica Posted September 11, 2007 Share Posted September 11, 2007 You'll need to use date() and strtotime() Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346323 Share on other sites More sharing options...
Woodburn2006 Posted September 11, 2007 Author Share Posted September 11, 2007 i tried: $date = 11/09/2007; $date = date('jS M', $date); and for some reason it came out as '31st Dec' which is the right format but wrong date Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346332 Share on other sites More sharing options...
Jessica Posted September 11, 2007 Share Posted September 11, 2007 You only used one of the functions I said. Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346333 Share on other sites More sharing options...
Woodburn2006 Posted September 11, 2007 Author Share Posted September 11, 2007 ok cool, my mistake $date = 11/09/2007; $date = strtotime("$date"); $date = date('jS M', $date); that works fine except the fact that it is reading it as an american date, but it is in a british date so it is reading it as if its 9th Nov instead of 11th Sep Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346339 Share on other sites More sharing options...
Jessica Posted September 11, 2007 Share Posted September 11, 2007 Ah. Well if you know it will always be the british date, you could use substr() to take the day and month numbers and switch them. If you can't figure out how to do that post again and I'll post it for you. Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346341 Share on other sites More sharing options...
Woodburn2006 Posted September 11, 2007 Author Share Posted September 11, 2007 ah sweet, i done it. used this: $day = substr("$date", 0, -; $month = substr("$date", 3, -5); $year = substr ("$date", -4); $date = "$month/$day/$year"; $date = strtotime("$date"); $date = date('jS M', $date); dont know if thats the long way round but it works? thanks Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346366 Share on other sites More sharing options...
Jessica Posted September 11, 2007 Share Posted September 11, 2007 That's how I'd do it. Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346367 Share on other sites More sharing options...
Dragen Posted September 11, 2007 Share Posted September 11, 2007 wouldn't this be easier: list($d, $m, $y) = explode('/', $date); $date = strtotime("$m/$d/$y"); $date = date('jS M', $date); Just a bit shorter, but should work as well Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346370 Share on other sites More sharing options...
Jessica Posted September 11, 2007 Share Posted September 11, 2007 Great idea Dragen. Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346376 Share on other sites More sharing options...
Woodburn2006 Posted September 11, 2007 Author Share Posted September 11, 2007 ideal, thanks alot Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346381 Share on other sites More sharing options...
Dragen Posted September 11, 2007 Share Posted September 11, 2007 no problem Link to comment https://forums.phpfreaks.com/topic/68906-date-format/#findComment-346394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.