Ouzo\Utilities\Date::formatDate PHP Method

formatDate() public static method

Returns formatted date.
public static formatDate ( string $date, string $format = 'Y-m-d' ) : null | string
$date string
$format string
return null | string
    public static function formatDate($date, $format = 'Y-m-d')
    {
        if (!$date) {
            return null;
        }
        $date = new DateTime($date);
        return $date->format($format);
    }

Usage Example

Beispiel #1
0
 /**
  * @test
  */
 public function shouldFormatDateCustomFormatter()
 {
     //given
     $date = '2013-05-10 16:32:30.147177';
     //when
     $formattedDate = Date::formatDate($date, 'Y/m/d');
     //then
     $this->assertEquals('2013/05/10', $formattedDate);
 }
All Usage Examples Of Ouzo\Utilities\Date::formatDate