Skip to content

Instantly share code, notes, and snippets.

<?php
date_default_timezone_set('America/Mexico_City');
$fechaInicio = new DateTime("2020-03-09 17:55:15");
$fechaFin = new DateTime("2022-01-01 17:45:25");
$intervalo = $fechaInicio->diff($fechaFin);
echo "La diferencia entre " . $fechaInicio->format('Y-m-d h:i:s') . " y " . $fechaFin->format('Y-m-d h:i:s') . " es de: <br> " . $intervalo->y . " años, " . $intervalo->m." meses, ".$intervalo->d." dias, " . $intervalo->h . " horas, " . $intervalo->i . " minutos y " . $intervalo->s . " segundos";
<?php
// Declaramos nuestras fechas inicial y final
$fechaInicial = date('2022-01-01');
$fechaFinal = date('2023-01-01');
// Las convertimos a segundos
$fechaInicialSegundos = strtotime($fechaInicial);
$fechaFinalSegundos = strtotime($fechaFinal);
// Hacemos las operaciones para calcular los dias entre las dos fechas y mostramos el resultado
// Resultado de convertir fechas a segundos con la funcion strtotime()
La fecha: 2022-08-28 al convertirla a segundos es igual a: 1661662800
La fecha con hora: 2022-08-28 01:04:36 al convertirla a segundos es igual a: 1661666676
<?php
date_default_timezone_set('America/Mexico_City'); //Especificamos zona horaria
$fechaActual = date('Y-m-d'); //Declaramos la fecha
$fechaSegundos = strtotime($fechaActual); //Convertimos a segundos
echo "La fecha: " . $fechaActual . " al convertirla a segundos es igual a: " . $fechaSegundos . "<br>"; //Mostramos resultados
$fechaHora = date('Y-m-d h:i:s');
<?php
date_default_timezone_set('America/Mexico_City');
$fechaInicial = date('2022-08-03 17:26:18');
$fechaEnSegundos = strtotime($fechaInicial);
$diasAumentar = 17;
$dia = 86400;
$contador = 1;
===SUMAR DIAS A FECHA CON PHP===
La fecha inicial es: 2022-08-03 02:55:55
Se le agregaron: 17 dias
la fecha final es: 2022-08-20 02:55:55
<?php
date_default_timezone_set('America/Mexico_City');
$fechaInicial = date('2022-08-03 02:55:55');
$fechaEnSegundos = strtotime($fechaInicial);
$diasAumentar = 17;
$dia = 86400;
for ($i=1; $i <= $diasAumentar ; $i++) {
<?php
$carpeta = glob('Archivos/*');
echo "<ul>";
foreach($carpeta as $archivo){
$porciones = explode("/", $archivo);
echo "<li>" . $porciones[1]. "------ " . filesize($archivo) . " bytes </li>" ;
}
echo "</ul>";
//Resultado
<?php
$dir_subida = 'Archivo/';
$fichero_subido = $dir_subida . basename($_FILES['fichero_usuario']['name']);
move_uploaded_file($_FILES['fichero_usuario']['tmp_name'], $fichero_subido);
header("Location: subeArchivo.php");
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Subir Archivos con PHP</title>
</head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">