Thu. Nov 21st, 2024

sarveshpathak.com

Code Snippets, Tutorials, Articles, Technical Stuff

How to Get Current Date Time in Multiple Formats in PHP

1 min read
How to Get Current Date Time in Multiple Formats in PHP

How to Get Current Date Time in Multiple Formats in PHP

Here we will understand the following points on How to get Current Date Time in Multiple Formats in PHP.

1. How to Get Current Date as year/month/date format

2- How to Get Current Date as the year-month-date format

3. How to Get Month Name and Date, Year Time format

4- How to Get Current Day Name

PHP Code: PHP date time with multiple example

<?php

date_default_timezone_set('Asia/Kolkata');
	$date=date("Y-m-d h:i:s A");
	echo $date. "<br>";
	//Get Current Date as year/month/date format
	echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
//Get Current Date as year-month-date format
echo "Today is " . date("Y-m-d") . "<br>";
//Get Current Day Name
echo "Today is " . date("l"). "<br>";

$today = date("F j, Y, g:i a");                 // Get Month Name and Date , Year Time March 10, 2001, 5:16 pm
echo $today. "<br>";
$today = date("m.d.y");                         // 03.10.01
echo $today. "<br>";
$today = date("j, n, Y");                       // 10, 3, 2001
echo $today. "<br>";
$today = date("Ymd");                           // 20010310
echo $today. "<br>";
$today = date('h-i-s, j-m-y');     // 05-16-18, 10-03-01
echo $today. "<br>";
$today = date('\T\o\d\a\y \i\s \t\h\e jS \d\a\y \o\f \m\o\n\t\h');   // it is the 10th day.
echo $today. "<br>";
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
echo $today. "<br>";

$today = date("H:i:s");                         // Get Time with Seconds
echo $today. "<br>";
$today = date("Y-m-d H:i:s");      
echo $today. "<br>";
	?>

PHP date time with multiple examples

Output: How to Get Current Date Time in Multiple Formats in PHP

Get Current Date Time in Multiple Formats
How to Get Current Date Time in Multiple Formats in PHP

Download Source Code

About Post Author

1 thought on “How to Get Current Date Time in Multiple Formats in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.