Created
December 11, 2019 14:54
-
-
Save IsaacAndres/a194267966879e88bb3b584f39b0ba50 to your computer and use it in GitHub Desktop.
Obtener el primer y último día del mes
This file contains 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
<?php | |
$fecha = new DateTime(); # Para obtener desde una fecha determinada sería de la siguente forma: $fecha = new DateTime('2019-12-11'); | |
// obtener primer día del mes | |
$primer = $fecha; | |
$primer->modify('first day of this month'); | |
$primer = $primer->format('Y-m-d'); | |
echo $primer; | |
// obtener último día del mes | |
$ultimo = $fecha; | |
$ultimo->modify('last day of this month'); | |
$ultimo = $ultimo->format('Y-m-d'); | |
echo $ultimo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment