Skip to content

Instantly share code, notes, and snippets.

@cristianciofu
Created June 22, 2013 10:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristianciofu/5840415 to your computer and use it in GitHub Desktop.
Save cristianciofu/5840415 to your computer and use it in GitHub Desktop.
Change php's DateTime behavior to use Monday as first day of the week
<?php
// found it here :
// http://stackoverflow.com/questions/13128854/php-datetime-class-change-first-day-of-the-week-to-monday
class EuroDateTime extends DateTime {
// Override "modify()"
public function modify($string) {
// Change the modifier string if needed
if ( $this->format('N') == 7 ) { // It's Sunday and we're calculating a day using relative weeks
$matches = array();
$pattern = '/this week|next week|previous week|last week/i';
if ( preg_match( $pattern, $string, $matches )) {
$string = str_replace($matches[0], '-7 days '.$matches[0], $string);
}
}
return parent::modify($string);
}
}
@TricksfortheWeb
Copy link

How can I make another day of the week (eg Wednesday) the first day?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment