pikrut
0
Q:

php get date

$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)
7
$timestamp = strtotime('2009-10-22');

$day = date('D', $timestamp);
var_dump($day);
4
$today = date("F j, Y, g:i a");               // March 10, 2001, 5:16 pm
$today = date("m.d.y");                       // 03.10.01
$today = date("j, n, Y");                     // 10, 3, 2001
$today = date("Ymd");                         // 20010310
$today = date('h-i-s, j-m-y, it is w Day');   // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.
$today = date("D M j G:i:s T Y");             // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');   // 17:03:18 m is month
$today = date("H:i:s");                       // 17:16:18
$today = date("Y-m-d H:i:s");                 // 2001-03-10 17:16:18 (the MySQL DATETIME format)
5
date('Y-m-d H:i:s')
2

 <?php
echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
echo "Today is " . date("Y-m-d") . "<br>";

 echo "Today is " . date("l");
?> 
7
//Get current date time in PHP

// Simply:
$date = date('Y-m-d H:i:s');

// Or:
$date = date('Y/m/d H:i:s');

// This would return the date in the following formats respectively:
$date = '2012-03-06 17:33:07';
// Or
$date = '2012/03/06 17:33:07';

/** 
 * This time is based on the default server time zone.
 * If you want the date in a different time zone,
 * say if you come from Nairobi, Kenya like I do, you can set
 * the time zone to Nairobi as shown below.
 */

date_default_timezone_set('Africa/Nairobi');

// Then call the date functions
$date = date('Y-m-d H:i:s');
// Or
$date = date('Y/m/d H:i:s');

// date_default_timezone_set() function is however
// supported by PHP version 5.1.0 or above.
0

 <?php
$d=mktime(11, 14, 54, 8, 12, 2014);
echo "Created date is " . date("Y-m-d h:i:sa", $d);
?> 
1
// Prints the day
echo date("l") . "<br>";
1
// 1. create a date instance
$date = new DateTime;

// 2. set the date using the setDate(year, month, date) method on the
//    $date instance
$date->setDate(1999,02,19);
1
$date_input = '2003';
$date_output= date( "Y-m-d", mktime( 0, 0, 0, 1, 1, $date_input ));
//date_output = 2003-01-01
0
date("Y-m-d h:i:sa")
0
<?php
print_r(getdate());
?>
 
-1

New to Communities?

Join the community