Showing posts with label Dates. Show all posts
Showing posts with label Dates. Show all posts

Monday, August 17, 2015

Server Time Zone to Local TimeZone in PHP

Barbie would have said, 'Time Math is Hard'.

JS to get TZ



PHP:
$myTZ = 'America/New_York'; //time zone that date/time is stored in
$urTZ = $row['timezone']; // stored local
$local_time_in = new DateTime($row['time_in'], new DateTimeZone($myTZ));
$local_time_out = new DateTime($row['time_out'],new DateTimeZone($myTZ));
$local_time_in->setTimeZone(new DateTimeZone($urTZ));
$local_time_out->setTimeZone(new DateTimeZone($urTZ));
$row['local_time_in'] = $local_time_in->format('Y-m-d H:i T');
$row['local_time_out'] =$local_time_out->format('Y-m-d H:i T');
                   

Tuesday, November 29, 2011

PHP: Payroll Dates


/***
* PayRoll Dates
* return array;
*/
  public function workDays($date='2011-12-17') 
  {
    if(!$date) {$date=strtotime("Last Saturday");
    } else { $date = strtotime($date); } 
  # find payroll dates ending last Saturday
    $workdays = array();
  # calculate 
    $workdays["sat"] = Date('Y-m-d', $date);
    $workdays["fri"] = Date('Y-m-d', strtotime('-1 day',$date));
    $workdays["thu"] = Date('Y-m-d', strtotime('-2 day',$date));
    $workdays["wed"] = Date('Y-m-d', strtotime('-3 day',$date));
    $workdays["tue"] = Date('Y-m-d', strtotime('-4 day',$date));
    $workdays["mon"] = Date('Y-m-d', strtotime('-5 day',$date));
    $workdays["sun"] = Date('Y-m-d', strtotime('-6 day',$date));

    $workdays["end"] = Date('Y-m-d', $date);
    $workdays["beg"] = Date('Y-m-d', strtotime('-6 day',$date));
    
#print_r($workdays);

    return $workdays;
  } 

Tuesday, April 05, 2011

PHP Date functions for Reports

Needed to pre-populate some datepickers, and it took me a while to remember how.

#common date functions for reporting
function getFirstDayOfMonth() {
  return date("Y-m-01");
}
function getLastDayOfMonth() {
  return date("Y-m-t");
}
function getLastDayofLastMonth() {
  return date("Y-m-t", strtotime('-1 month',time()));
}
function getFirstDayofLastMonth() {
  return date("Y-m-01", strtotime('-1 month',time()));
}