The Web Blinders logo

Programming

PHP getting Date in YYYY-MM-DD and DD-MM-YYYY

<?php
$date=date('Y-m-d');

// returns current date in YYYY-MM-DD
// For eg: 2019-06-24
var_dump($date);


// For DD-MM-YYYY format
$date=date('d-m-Y');
var_dump($date);
// For eg: 24-06-2019

PHP getting time in HH:MM:SS

<?php
$time=date('H:i:s');

var_dump($time);
// returns time in hours : minutes : seconds
// For eg: 14:41:24

PHP getting current day , month and year

<?php
$year=date('Y');

// full year
var_dump($year); // For eg: 2019

// present month 
$month=date('m');
var_dump($month); // For Eg: 06

// day
$day=date('d');
var_dump($day);  // For Eg: 24

PHP getting Date and Time in YYYY-MM-DD HH:MM:SS

<?php
$dateTime=date('Y-m-d H:i:s');

// returns current date time in YYYY-MM-DD HH:MM:SS
var_dump($dateTime);

// For eg: 2019-06-24 14:21:19

This is also the format for MySql Datetime.So this will help you create a MySql's DateTime value using PHP

Visit official documentation to know different characters recognized in the date().

Need developers ?

if so, send a message.

thewebblinders@gmail.com

More Programming from our blog

SEARCH FOR ARTICLES