get actual date php code example

Example 1: php get current date and time

$today = date("F j, Y, g:i a");   // October 30, 2019, 10:42 pm
$today = date("D M j G:i:s T Y"); // Wed Oct 30 22:42:18 UTC 2019
$today = date("Y-m-d H:i:s");     // 2019-10-30 22:42:18(MySQL DATETIME format)

Example 2: date now php

date('Y-m-d H:i:s')

Example 3: php format date

<?php
  // To change the format of an existing date
  $old_date_format = "20/03/1999";
  $new_data_format = date("Y-m-d H:i:s", strtotime($old_date_format));

Example 4: php current date get

date_default_timezone_set('Asia/Kolkata'); 
echo date("Y-m-d H:i:s"); // time in India

Example 5: php current date

# Current date
date_default_timezone_set('Asia/Kolkata'); 
echo date("Y-m-d H:i:s"); 

# Current Time
date_default_timezone_set("America/New_York");
echo "The time is " . date("h:i:sa");

Example 6: phph date

<?php
// Définit le fuseau horaire par défaut à utiliser. Disponible depuis PHP 5.1
date_default_timezone_set('UTC');


// Affichage de quelque chose comme : Monday
echo date("l");

// Affichage de quelque chose comme : Monday 8th of August 2005 03:12:46 PM
echo date('l jS \of F Y h:i:s A');

// Affiche : July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));

/* utilise les constantes dans le paramètre format */
// Affichage de quelque chose comme : Wed, 25 Sep 2013 15:28:57 -0700
echo date(DATE_RFC2822);

// Affichage de quelque chose comme : 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
?>

Tags:

Cpp Example