So, I'm getting my date from MySQL in the yyyy-mm-dd format into the variable $a_row['date'] and I wanted to display it as Jan 15, 2004 so I did this:
$date = explode ( "-", $a_row['date'] );
$year = $date[0];
$month = $date[1];
$day = $date[2];
$ts = mktime( 0, 0, 0, $month, $day, $year );
$date = date( "F j Y", $ts );
$date = explode( " ", $date );
$month = substr( $date[0], 0, 3 );
$date = $month." ".$date[1].", ".$date[2];
print $date;
It works perfectly. First try, even! pulls muscle patting self on back 😃 I was just wondering if anyone could think of a more concise way of doing this.
I know I could change this:
$year = $date[0];
$month = $date[1];
$day = $date[2];
$ts = mktime( 0, 0, 0, $month, $day, $year );
to:
$ts = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
but I guess i liked the clarity of $ts = mktime( 0, 0, 0, $month, $day, $year );