Let’s see how to convert a date from yyyy-mm-dd hh:mm:ss
to yyyymmddhhmmss
. This can be useful when you’ll use sort functions for example (such as asort()
).
Elegant:
/**
* Format from "yyyy-mm-dd hh:mm:ss" to "yyyymmddhhmmss"
*/
function plainDate( $d )
{
return( preg_replace( '/(-|:|\040)/', '', $d ) );
}
Obvious:
/**
* Format from "yyyy-mm-dd hh:mm:ss" to "yyyymmddhhmmss"
*/
function plainDate( $d )
{
return( str_replace( ' ', '', str_replace('-','', str_replace(':', '', $d) ) ) );
}
Insane:
function plainDate( $d )
{
$pd = explode(' ', $d);
$dd = explode('-', $pd[0]);
$hp = explode(':', $pd[1]);
return( $dd[0].$dd[1].$dd[2].$hp[0].$hp[1].$hp[2] );
}