Table of Contents                    
                hide            
            
Example: Php code to display current Day.
<!DOCTYPE html>
<html>
	<body>			
		<?php
				
		   echo "Today is ". date("l") . ".";
                   echo "Today is ". date("w") . ".";			
		?>
			
	</body>
</html>
Output : 
Today is Wednesday.
Today is 3.
NB: 
- Small letter(l) is used to display current system day.
- The numeric representation of Sunday is 0.Example: Php code to display the different date formats.
<!DOCTYPE html>
<html>
	<body>			
		<?php
				
		   echo date("l jS \of F Y h:i:s A");
                   echo date("l jS \of F Y h:i:s a");
                   echo date("D jS \of F Y h:i:s a");
                   echo "Today is ".date("z") . " days of this year.";
                   echo date("jS F Y");
                   echo date("j - m - Y") . ".";
                   echo date("j - M - Y").".";
                   echo date("j - n - Y").".";
                   echo date("j - M - y").".";
                   echo date("z").".";
                   echo "The ".date("F")." month is of ".date("t") . " days.";
                   echo " Current year is " . date("Y");
                   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 "<br>";
		   echo "Today is " . date("m/d/Y") . "<br>";
		   echo "Today is " . date("m.d.Y") . "<br>";
		   echo "Today is " . date("m-d-Y") . "<br>";
		   echo "<br>";
		   echo "Today is " . date("d/m/Y") . "<br>";
		   echo "Today is " . date("d.m.Y") . "<br>";
		   echo "Today is " . date("d-m-Y") . "<br>";
                   echo date("F j, Y, g:i a")."<br>";
		   echo date('\T\o\d\a\y \i\s jS \d\a\y.')."<br>";
		   echo date("D M j G:i:s T Y")."<br>";
                   echo date("d/m/Y h:i:s a", time());  	
		?>			
	</body>
</html>
Output :
 
Wednesday 26th of August 2020 01:09:51 AM
Wednesday 26th of August 2020 01:09:51 am
Wed 26th of August 2020 01:09:51 am
Today is 238 days of this year.
26th August 2020
26 - 08 - 2020.
26 - 8 - 2020.
26 - Aug - 2020.
26 - Aug - 20.
The August month is of 31 days.
Current year is 2020
Today is 2020/08/26
Today is 2020.08.26
Today is 2020-08-26
Today is 08/26/2020
Today is 08.26.2020
Today is 08-26-2020
Today is 26/08/2020
Today is 26.08.2020
Today is 26-08-2020
August 27, 2020, 8:16 pm
Today is 27th day.
Thu Aug 27 20:16:40 CEST 2020
27/08/2020 08:22:19 pmExample : Source codes to display the different Time & Calendar in Php.
<!DOCTYPE html>
<html>
	<body>		
		<?php
		   echo "The time format is " . date("H:i:s a"). "<br>";
		   echo "The time format is " . date("H:i:s A"). "<br>";
		   echo "The time format is " . date("H:i a"). "<br>";
	           echo "The time format is " . date("H:i A"). "<br>";
			
		   echo "<br>";
			
		   echo "The time format is " . date("h:i:s a"). "<br>";
		   echo "The time format is " . date("h:i:s A"). "<br>";
		   echo "The time format is " . date("h:i a"). "<br>";			
		   echo "The time format is " . date("h:i A"). "<br>";			
		?>	
	</body>
</html>
Output :
The time format is 16:23:19 pm
The time format is 16:23:19 PM
The time format is 16:23 pm
The time format is 16:23 PM
The time format is 04:23:19 pm
The time format is 04:23:19 PM
The time format is 04:23 pm
The time format is 04:23 PMExample : Php code to check whether the current year is Leap year or not.
<!DOCTYPE html>
<html>
	<body>		
		<?php			
			$x= date("L");
			if($x==1)
			{
			echo("This year has Leap Year.<br>");
			}
			else
			{
			echo("This year has not Leap Year.<br>");
			}
		?>			
	</body>
</html>Example : Different format of Date & Time difference in Php.
<!DOCTYPE html>
<html>
	<body>		
	   <?php
		$tdt1=strtotime("today");
		echo "Today's date & time is " . date("d-m-Y h:i:s a", $tdt1) . "<br>";
		echo "<br>";
		$tdt2=strtotime("tomorrow");
		echo "Tomorrow date is " . date("d-m-Y", $tdt2) . "<br>";
		echo "<br>";
		$tdt3=strtotime("previous day");
		echo "Previous day was " . date("d-m-Y", $tdt3) . "<br>";
			
		$tdt4=strtotime("last day");
		echo "Last day was " . date("d-m-Y", $tdt4) . "<br>";
			
		$tdt5=strtotime("Yesterday");
		echo "Yesterday was " . date("d-m-Y", $tdt5) . "<br>";
		echo "<br>";
		$tdt6=strtotime("next Monday");
		echo "Next Monday is " . date("d-m-Y", $tdt6) . "<br>";
		echo "<br>";
		$tdt7=strtotime("last Friday");
		echo "Last Friday was " . date("d-m-Y", $tdt7) . "<br>";
		echo "<br>";
		$tdt8=strtotime("+5 Months");
		echo "Five Month ahead is " . date("d-m-Y", $tdt8) . "<br>";
		echo "<br>";
		$tdt9=strtotime("-2 Months");
		echo "Two Month Back is " . date("d-m-Y", $tdt9) . "<br>";		
		echo "<br>";			
		$tdt10=strtotime("+ 2 week");
		echo "Two week ahead is " . date("d-m-Y", $tdt10) . "<br>";		
		echo "<br>";
		$tdt11=strtotime("- 2 week");
		echo "Two week back is " . date("d-m-Y", $tdt11) . "<br>";		
		echo "<br>";
		?>	
	</body>
</html>
Output :
Today's date & time is 27-08-2020 12:00:00 am
Tomorrow date is 28-08-2020
Previous day was 26-08-2020
Last day was 26-08-2020
Yesterday was 26-08-2020
Next Monday is 31-08-2020
Last Friday was 21-08-2020
Five Month ahead is 27-01-2021
Two Month Back is 27-06-2020
Two week ahead is 10-09-2020
Two week back is 13-08-2020StackOverFlow link for PHP Date & Time codes
 
0 Comments