Skip to content

Instantly share code, notes, and snippets.

@alexalannunes
Forked from franciscopessoa/mesComercial.php
Created February 1, 2020 17:56
Show Gist options
  • Save alexalannunes/921fee170b39d1c8810e3b49924e69f4 to your computer and use it in GitHub Desktop.
Save alexalannunes/921fee170b39d1c8810e3b49924e69f4 to your computer and use it in GitHub Desktop.
Calcular mês comercial, 26 a 25
<?php
function dataCompetencia($data)
{
$dia = (int) substr($data, 8, 2);
$AnoMes = substr($data, 0, 7);
if ($dia >= 26) {
$date['inicial'] = $AnoMes . '-26';
$date['final'] = date('Y-m', strtotime('+ 1 Month', strtotime($AnoMes))) . '-25';
} else {
$date['inicial'] = date('Y-m', strtotime('- 1 Month', strtotime($AnoMes))) . '-26';
$date['final'] = $AnoMes . '-25';
}
return $date;
}
print_r(dataCompetencia(date('Y-m-d')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment