PHP Knowledge Base

Get and display data from a function

Class
<?php 
  
class getDateInfo
{
	private $year;
	private $week;
	
	function __construct($year, $week) {
		$this->year = $year;
		$this->week = $week;		
		}
	
	function dateInfo()
	{
		$dto = new DateTime();
		$dto->setISODate($this->year, $this->week);		
		
		$this->fullDate = $dto->setISODate($this->year, $this->week, 2)->format('D M d, Y');
	}
	
	function get_fullDate() {
		return $this->fullDate;
	}
}
  
?>
Demo #1
<?php 
include "class.php";

$report__current_week__year = "2019";
$report__current_week__week = "46";

$reportDate = new getDateInfo($report__current_week__year, $report__current_week__week);
$reportDate->dateInfo();
$reportDate__date = $reportDate->get_fullDate();

echo "<p>$reportDate__date</p>"
?>

demo

Demo #2
<?php 
include "class.php";

$report__current_week__year = "2019";
$report__current_week__week = "46";

$reportDate = new getDateInfo($report__current_week__year, $report__current_week__week);
$reportDate->dateInfo();
?>

<p><?php echo $reportDate->get_fullDate(); ?></p>

demo