How to Get Current Date and Time in PHP?

Question: how to get todays date in php?, how to get today’s date in php?, get today’s date in php,How to Get Current Date and Time in PHP?

Answer: Use the DateTime() Class: & PHP date() Function with Examples

Get Current Date and Time in PHP

You can use PHP date() function or DateTime() class to get current Date & Time in PHP. This Article, will help you to get current date time in PHP.

The provided outputs based on the timezone settings in the PHP main Config php.ini file. You may should to update this custom setting to get date and time in the need a current country relavnts timezone. Read this Article to set timezone in settings of the PHP configuration.

get today's date in php, php get current date and time, get todays date in php, php get current date time, how to get today's date in php,
php get current date and time

Using date() Function

PHP date() function converts the timestamp stored in computer memory in a human-readable format.

  Laravel 6 csrf tokens in ajax calls

PHP Date Syntax & Example

PHP syntax

The syntax of PHP date() function is as:

 date(format, [timestamp])

The below php Example will return current get today’s datetime in ‘Y-m-d H:i:s’ Popular format.

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

Result:- get today’s date in php

2021-11-25 08:14:12

Other useful examples:

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

php today’s date dd-mm-yyyy

  date('Y/m/d');           //  2021/11/25
  date('m/d/Y');           //  11/25/2021
  date('H:i:s');           //  08:14:12
  date('Y-m-d H:i:s');     //  2021-11-25 08:14:12

Get Your Time Zone

php get current timezone date and time

<?php
date_default_timezone_set("America/New_York");
echo "The timezone is " . date("h:i:sa");
?>

how to get todays date in php, php get today date, get the current date in php, how get current date in php, get todays date php, php get current date for mysql,
common date format characters

Using DateTime() Class:

The simple DateTime() PHP class functions allow you to get today’s date in php. You can also use PHP functions to format the Current date with time in multiple different types.

PHP DateTime() Class Example

<?php
    $getTodaysDate = new DateTime();
    echo $getTodaysDate->format('Y-m-d H:i:s');
?>

Result:-

2021-11-25 08:14:12

Here are list of the popular common PHP date format characters as well as their Key and data values.

  PHP Stripe api Send Accept Payment Integration

PHP Date function reference

The Datetime Screen shot below shows the common all the related PHP Time parameters, Day parameters, Month Parameters, Year Parameters used when working with the get current datetime in php function.

PHP Time parameters

php get current date and time as string, php get current date in yyyy-mm-dd format, php today's date yyyy-mm-dd, get todays date time php,
PHP Time parameters

PHP Day parameters

php today date only, get current date using php, get now date in php, php get current date with timezone, php get date 5 days ago,
Day parameters

PHP Month Parameters

php get current date only, php get current date timestamp, php today's date dd-mm-yyyy, php get current date in milliseconds, php get todays date, php 7 get current date, php 7 get current datetime, how get today date in php
Month Parameters

PHP Year Parameters

php datetime, datetime in php, php datetime format, php current datetime, current datetime in php, datetime php, datetime difference in php, datetime format in php, convert string to datetime php, get date from datetime in php
Year Parameters

You can get the More References in PHP :Website functions Like http://php.net/manual/en/function.date.php and http://php.net/manual/en/intro.datetime.php

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about how to get todays date in php?.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Get Facebook Access Token Using PHP SDK - Authentication
  2.   Calculate the difference between two dates using PHP
  3.   Split Laravel Routes into Multiple Files Example
  4.   PHP Multiple Checkbox Array Handling Tutorial Example
  5.   PHP Get Folder Path From File Path Examples
  6.   Difference between two dates in years, months, days in PHP
  7.   Woocommerce Get product category name in array
  8.   Get Current Url Parameter using Laravel
  9.   Ajax Autocomplete Live Search Suggestion using PHP MySQL
  10.   Convert object to Array in PHP Example

Leave a Reply

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