Archive for the ‘PHP’ Category

Use the below example to convert from UTC to PDT

$timeZone = 'PDT';  //timezone to be converted
$dateSrc = '2014-11-08 07:00:00';
$dateTime = new DateTime($dateSrc, new DateTimeZone('UTC'));
$dateTime->setTimeZone(new DateTimeZone($timeZone));
echo 'Converted Date: '.$dateTime->format('Y-m-d H:i:s')

Advertisements
// sample $arrDate array

Array ( [0] => stdClass Object ( [date] => 2013-06-22 ) [1] => stdClass Object ( [date] => 2013-06-29 )
)



Use the following code to sort the associate array by date as one field

function sortByDate($a,$b){
                $t1 = strtotime($a->date);
                $t2 = strtotime($b->date);
                if ($t1 == $t2) {
                return 0;
                }
                return ($t1 < $t2) ? -1 : 1;
        }
        
    usort($arrData,"sortByDate");