Skip to content

Instantly share code, notes, and snippets.

@fedir
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedir/7fe0d3edb9a157009d6d to your computer and use it in GitHub Desktop.
Save fedir/7fe0d3edb9a157009d6d to your computer and use it in GitHub Desktop.
php times
<?php
$now = time();
$curMonth = date('n');
$curYear = date('Y');
if ($curMonth == 12) {
$currentMonthEnds = mktime(0, 0, 0, 1, 1, $curYear+1);
} else {
$currentMonthEnds = mktime(0, 0, 0, $curMonth+1, 1, $curYear);
}
echo date("Y-m-d H:i:s", $currentMonthEnds);
<?php
$now = time();
## Identifying current WE
// Next saturday begins
echo date( "Y-m-d H:i:s", strtotime( "next saturday" ) );
// Next sunday ends
echo date( "Y-m-d H:i:s", strtotime( "next monday" ) );
// Checking if the WE is already begins
if(strtotime( "next saturday" ) > strtotime( "next monday" ) ) {
// Or NO, it's already weekend
$weBegins = $now;
$weEnds = strtotime( "next monday" );
} else {
$weBegins = strtotime( "next saturday" );
$weEnds = strtotime( "next monday" );
}
<?php
$now = time();
## Identifying current week
// Next sunday ends
echo date( "Y-m-d H:i:s", strtotime( "next monday" ) );
// Checking if the WE is already begins
$weekBegins = $now;
$weekEnds = strtotime( "next monday" );
<?php
date_default_timezone_set("Europe/Paris");
$now = time();
$curMonth = date('n');
$curYear = date('Y');
if ($curMonth == 12) {
$currentMonthEnds = mktime(0, 0, 0, 1, 1, $curYear+1);
} else {
$currentMonthEnds = mktime(0, 0, 0, $curMonth+1, 1, $curYear);
}
echo date("Y-m-d H:i:s", $currentMonthEnds);
$nextMonthEnds = strtotime("+7 month first day midnight");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment