Last active
August 24, 2017 14:31
-
-
Save suresh-kumara-gist/9994e12192149563d9cb55d9d6b143b5 to your computer and use it in GitHub Desktop.
find last sunday and -1 week in drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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