Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save suresh-kumara-gist/9994e12192149563d9cb55d9d6b143b5 to your computer and use it in GitHub Desktop.
Save suresh-kumara-gist/9994e12192149563d9cb55d9d6b143b5 to your computer and use it in GitHub Desktop.
find last sunday and -1 week in drupal 8
use Drupal\Component\Datetime\DateTimePlus;
$format = "D";
$current_date = new DateTimePlus();
$current_timezone = date_default_timezone_get();
date_default_timezone_set("UTC");
$current_day = $current_date->format($format, ['timezone' => drupal_get_user_timezone()]);
$lastweek = 'last Sunday -1 week';
$dateformat = 'Y-m-d\TH:i:s';
if ($current_day != "Sun") {
$lastsundaydate = new DateTimePlus($lastweek);
$lastsundaydate = $lastsundaydate->format($dateformat, ['timezone' => drupal_get_user_timezone()]);
}
date_default_timezone_set($current_timezone);
dpm($lastsundaydate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment