gple Posted December 22, 2006 Share Posted December 22, 2006 I have a variable $date which when outputted appears as (2007-12-01). What do I need to do so it outputs like (12-01-2007) or (12/01/2007) without using substrings. Link to comment https://forums.phpfreaks.com/topic/31594-date-formatting/ Share on other sites More sharing options...
wildteen88 Posted December 22, 2006 Share Posted December 22, 2006 convert it to a unix timestamp (use strtotime) and then reformat it with the date function example:[code=php:0]$date = '12-01-2007';// covert the date to a unix timestamp$ut_date = strtotime($date);// chanes the date to the following format:// dd/mm/yyyy$n_date = date("d/m/Y", $ut_date);// echo the new formatted dateecho $n_date;[/code] Link to comment https://forums.phpfreaks.com/topic/31594-date-formatting/#findComment-146438 Share on other sites More sharing options...
Nicklas Posted December 22, 2006 Share Posted December 22, 2006 Take a look at [url=http://www.php.net/strtotime]strtotime()[/url]ex[CODE]<?php$date = '2007-12-01';echo date("m-d-Y", strtotime($date));?>[/CODE] Link to comment https://forums.phpfreaks.com/topic/31594-date-formatting/#findComment-146439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.