You are currently viewing How to Get Today’s Date in PHP | Step by Step Guide
  • Post category:PHP

How to Get Today’s Date in PHP | Step by Step Guide

php get today’s date

In this article, we will see How to get today’s date in PHP.

How to get a date in PHP

PHP default timezone set(timeZoneName:string) is used to get the date and time relative to local time zone or local date and time.
Ex: date_default_timezone_set(“Asia/kolkata”);

Note: list of time zone names by country:

date(format:string):string
It returns the date and time according to the given string format
Ex: echo date(“d/m/y h:i;s A”)

Using string formatting characters

Get day:

echo date(“d”); //returns the day of the month (01 to 31) (numeric representation)
echo date(“D”); //returns day of the week(Mon to Sun) (short textual representation)
echo date(“I”); //returns day of the week(Monday to Sunday) (long textural representation)

Get day

echo date(“m”); //returns the month of the year (01 to 12) (numeric representation)
echo date(“M”); //returns the month of the year (Jan to Dec) (short textual representation)
echo date(“F”); //returns the month of the year (January to December) (long textural representation)

Get day

echo date(“Y”); //returns year in 4 digits
echo date(“y”); //returns year in 2 digits

Example code:

<?php
date_default_timezone_set("Asia/kolkata");

echo date("d/m/y")

/*
output:
12/3/2022
*/
?>

Leave a Reply