Obtener la fecha actual:
print date('d-M-Y'); //Otros formatos: $hoy = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm $hoy = date("m.d.y"); // 03.10.01 $hoy = date("j, n, Y"); // 10, 3, 2001 $hoy = date("Ymd"); // 20010310 $hoy = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01 $hoy = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day. $hoy = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001 $hoy = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month $hoy = date("H:i:s"); // 17:16:18 $hoy = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (el formato DATETIME de MySQL)
Crear una fecha:
mktime (hora,minuto,segundo,mes,dia,año) $mañana = mktime(0, 0, 0, date("m") , date("d")+1, date("Y")); $mes_anterior = mktime(0, 0, 0, date("m")-1, date("d"), date("Y")); $año_siguiente = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);
Convertir cadenas en fecha:
echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week"), "\n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; echo strtotime("next Thursday"), "\n"; echo strtotime("last Monday"), "\n";