Tuesday, November 19, 2024
Google search engine
HomeLanguagesPHP | DatePeriod getStartDate() Function

PHP | DatePeriod getStartDate() Function

The DatePeriod::getStartDate() function is an inbuilt function in PHP which is used to return the start date of the given date period.

Syntax:

DateTimeInterface DatePeriod::getStartDate( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns the start date of the given date period.

Below programs illustrate the DatePeriod::getStartDate() function in PHP:

Program 1:




<?php
  
// Initialising a startDate with time
$StartDate = new DateTime('2019-05-16T00:00:00Z');
  
// Initialising a DateInterval of 2 day
$DateInterval = new DateInterval('P2D');
  
// Initialising a endDate with time
$EndDate = new DateTime('2019-05-20T00:00:00Z');
  
// Initialising a DatePeriod with startDate, DateInterval and
// endDate 
$datePeriod = new DatePeriod( $StartDate, $DateInterval, $EndDate);
      
// Calling the getStartDate() function
$StartDate = $datePeriod->getStartDate();
  
// Getting the start date
echo $StartDate->format(DateTime::ISO8601);
  
?>


Output:

2019-05-16T00:00:00+0000

Program 2:




<?php
  
// Initialising a DatePeriod with a date of 2019-09-30,
// time of 10 hours, 40 minutes and 44 seconds and with
// day period of 14 days
$datePeriod = new DatePeriod('R7/2019-09-30T10:40:44Z/P14D');
      
// Calling the getStartDate() function
$StartDate = $datePeriod->getStartDate();
  
// Getting the start date
echo $StartDate->format(DateTime::ISO8601);
?>


Output:

2019-09-30T10:40:44+0000

Reference: https://www.php.net/manual/en/dateperiod.getstartdate.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments