Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ErMandeep/f90709e90248a6e250ba97fc99eb1a1a to your computer and use it in GitHub Desktop.
Save ErMandeep/f90709e90248a6e250ba97fc99eb1a1a to your computer and use it in GitHub Desktop.
last 7 days, last 2 weeks and last 30 days in php
<?php
if( !function_exists( 'pr' ) ) {
function pr() {
foreach( func_get_args() as $e ) {
echo "<pre>";
print_r( $e );
echo "</pre>";
}
}
}
$current_date = date('Y-m-d');
$yesterday_date = date('Y-m-d', strtotime('-1 day', strtotime($current_date)));
$lastSevenDays = array('from' => date('Y-m-d', strtotime('-7 day', strtotime($current_date))), 'to' => $yesterday_date);
$lastTwoWeeks = array('from' => date('Y-m-d', strtotime('-14 day', strtotime($current_date))), 'to' => $yesterday_date);
$lastMonth = array('from' => date('Y-m-d', strtotime('-30 day', strtotime($current_date))), 'to' => $yesterday_date);
pr( "last Seven Days ========================= ", $lastSevenDays , 'last Two Weeks ========================== ', $lastTwoWeeks, 'last Month ===============================', $lastMonth );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment