Answers for "php function to find day of the week from date"

PHP
0

php check weekday of date

$dayofweek = date('w', strtotime($date));
$result    = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));
Posted by: Guest on April-29-2020
3

php week of a date

Things to be aware of when using week numbers with years.

<?php
echo date("YW", strtotime("2011-01-07")); // gives 201101
echo date("YW", strtotime("2011-12-31")); // gives 201152
echo date("YW", strtotime("2011-01-01")); // gives 201152 too
?>

BUT

<?php
echo date("oW", strtotime("2011-01-07")); // gives 201101
echo date("oW", strtotime("2011-12-31")); // gives 201152
echo date("oW", strtotime("2011-01-01")); // gives 201052 (Year is different than previous example)
?>

Reason:
Y is year from the date
o is ISO-8601 year number
W is ISO-8601 week number of year

Conclusion:
if using 'W' for the week number use 'o' for the year.
Posted by: Guest on March-28-2020
0

week starting date and end date in php

<?php
	$week=29;
	$year=2017;
	
  function getStartAndEndDate($week, $year)
  {  
    $dateTime = new DateTime();  
    $dateTime->setISODate($year, $week); 
    $result['start_date'] = $dateTime->format('d-M-Y');
    $dateTime->modify('+6 days'); 
    $result['end_date'] = $dateTime->format('d-M-Y'); 
    return $result;
  }

  $dates=getStartAndEndDate($week,$year);
	print_r($dates);

?>
Posted by: Guest on April-14-2021
0

how to check the day of any date in php

// how to check the day of any date in php?

//Our YYYY-MM-DD date string.
$date = $request->start_date;

//Convert the date string into a unix timestamp.
$unixTimestamp = strtotime($date);

//Get the day of the week using PHP's date function.
$dayOfWeek = date("l", $unixTimestamp);

//Print out the day that our date fell on.
$day = $date . ' fell on a ' . $dayOfWeek;
Posted by: Guest on March-05-2021

Code answers related to "php function to find day of the week from date"

Browse Popular Code Answers by Language