[ create a new paste ] login | about

Link: http://codepad.org/Cpfgig7R    [ raw code | output | fork ]

PHP, pasted on Nov 2:
1
2
3
4
5
6
7
8
9
10
<?php
function formatDate($d)
{
    $f = 'Y-m-d' . (date('H:i:s', strtotime($d)) != '00:00:00' ? ' H:i:s' : '');
    $date = new DateTime($d);
    return $date->format($f);
}
echo(formatDate("2014-11-02 02:04:05").'<br>');
echo(formatDate("2014-11-02 00:00:00").'<br>');
?>


Output:
1
2014-11-02 02:04:05<br>2014-11-02<br>


Create a new paste based on this one


Comments: