Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <?php
  2. $hora="21:30";
  3. //declaracion variables
  4.  
  5. //codigo: Crearemos dos objetos fecha,
  6. // una la actual y otra a la medianoche
  7. //Luego las restaremos para ver la diferencia
  8. $fecha1=new DateTime('2019-12-31 '.$hora);
  9. $fecha2=date_create('2020-01-01 00:00:00');
  10.  
  11. $diferencia = $fecha2->diff($fecha1);
  12.  
  13. //$diferencia = date_diff($fecha2, $fecha1);
  14. $horas=$diferencia->h;
  15. $minutos=$diferencia->i;
  16. $queda = $horas * 60 + $minutos;
  17. echo "Para la medianoche quedan: " . $queda;
  18.  
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement