Skip to content
Advertisement

Get week range with timezone

I’m trying to get week range for a given date. I use the below code to do so.

 /**
 * get week range with timezones. GTM+1 or UTC+1
 * @return array
 */
function get_week_range(){
    $current_date = date('d/m/Y');
    //Add 1 hour to get the right timezone (GMT+1)
    $current_date = date('d/m/Y H:i:s', strtotime($current_date) + 3600);
    

    $week_range = array();
    $week_range['start'] = date('d/m/Y', strtotime('last saturday', strtotime($current_date)));
    $week_range['end'] = date('d/m/Y', strtotime('next saturday', strtotime($current_date)));

    return $week_range;
}

How can I make it work so it take timezone into account? My timezone is GMT+1 but the returned date has – 1 hour difference

Advertisement

Answer

You can use date_default_timezone_set() for that.

https://www.php.net/manual/en/function.date-default-timezone-set.php

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement