Ex No: 8 Write a program to Perform Date and Time Functions
Aim: To perform Date and Time operation using php
Algorithm
Step1: Design a webpage to perform Date and Time Operations.
Step2: Display the results of the following functions.
   A) date function to display current date.
   B) date function to display current date in different format.
   C) date function to display current time.
   D) time function to display the epoch timestamp.
   E) date_default_timezone_get function to display current timezone.
   F) date_default_timezone_set function to set current timezone to "Asia/Calcutta" and date function to display current time.
   G) strtotime function to convert a string to date and date function to display the date.
   H) strtotime function to convert "tomorrow" to date and date function to display the date.
   I) strtotime function to convert "+1 week" to date and date function to display the date.
   J) strtotime function to convert "next sunday" to date and date function to display the date.
   K) Display all Monday's in January 2018.
    i) Use strtotime function to assign "01 Jan 2018" as startdate.
    ii) Use strtotime function to assign "+30 days" from startdate as enddate.
    iii) while startdate less than enddate do.
                    a) Check if Day of the startdate is "Mon"
                        1) Display the date.
                    b) Increment the value of startdate by one.
            
<html>
<head>
 <meta charset="utf-8">
 <title>Date and Time</title>
 <style>
  td {
  	border-bottom: dotted 1px;
  }
 </style>
</head>
<body>
 <h3><u>Date Time Functions</u></h3>
  <form name="datetime" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   <table>    
    <tr >	  
	 <td>
	  Todays Date(d-m-y):
	 </td>
	 <td width="50%">
	  <?php echo date("d-m-y"); ?>
	 </td>
	</tr>
    <tr>	  
	 <td>
	  Todays Date:
	 </td>
	 <td>
	  <?php echo date("d M Y(l)"); ?>
	 </td>
	</tr>    
    <tr>	  
	 <td width="50%">
	  Time:
	 </td>
	 <td width="50%">
	  <?php echo date("H:i:sa"); ?>
	 </td>
	</tr>
	<tr>
	 <td>
	  Timestamp: 
	 </td>
	 <td>
	  <?php echo time(); ?>
	 </td>
	</tr>
	<tr>
	 <td>
	  Timezone: 
	 </td>
	 <td>
	  <?php echo date_default_timezone_get(); ?>
	 </td>
	</tr>
	<tr>
	 <td>
	  Timezone Set (Asia/Calcutta): 
	 </td>
	 <td>
	  <?php 
	   date_default_timezone_set("Asia/Calcutta");
	   echo date("H:i:sa"); 
	  ?>
	 </td>
	</tr>
	<tr>
	 <td colspan="2">
	  <b>String To Time Functions</b>
	 </td>
	</tr>
	<tr>
	 <td>
	  January 20 2014:  
	 </td>
	 <td>
	  <?php 
	   $date = strtotime("January 20 2014") ;
	   echo date("d-m-Y",$date);
	  ?>
	 </td>
	</tr>
	<tr>
	 <td>
	  Tomorrow's Date: 
	 </td>
	 <td>
	 <?php 
	  $date = strtotime("tomorrow") ;
	  echo date("d-m-Y",$date);
	 ?>
	 </td>
	</tr>
	 <td>
	  1 week from today Date: 
	 </td>
	 <td>
	 <?php 
	  $date = strtotime("+1 week") ;
	  echo date("d-m-Y",$date);
	 ?>
	 </td>
	</tr>
	<tr>
	 <td>
	  	Next Sunday's Date: 
	 </td>
	 <td>
	 <?php 
	  $date = strtotime("next sunday") ;
	  echo date("d-m-Y",$date);
	 ?>
	 </td>
	</tr>
	<tr>
	 <td>
	  Display Monday's in January(2018): 
	 </td>
	 <td>
	 <?php 
	  $stdate = strtotime("01 Jan 2018") ;
	  $enddate = strtotime("+30 days", $stdate);
	  while($stdate<$enddate)
	  {		   
	   if(date("D",$stdate)=="Mon")
	    echo date("d-m-Y",$stdate)."<br>";
	   $stdate = strtotime("+1day",$stdate);
	  }	  	  
	 ?>
	 </td>
	</tr>
  </table>
 </form>
 </body>
</html>
            
Result: Thus a webpage is designed using php perform Date and Time functions.