Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php check weekday of date

$dayofweek = date('w', strtotime($date));
$result    = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));
Comment

week day php

date('l'); //Returns full day name of the week: Thursday
date('D'); //Returns abbreviated day name of the week: Thu
Comment

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.
Comment

php get day of week number

echo date('d', strtotime('2022-02-02')); // 02
echo date('j', strtotime('2022-02-02')); // 2
Comment

PREVIOUS NEXT
Code Example
Php :: if button is clicked php 
Php :: get single row in codeigniter 
Php :: checking php version 
Php :: maximum characters laravel validation 
Php :: laravel 8 selecet the 2nd to the last record 
Php :: escape url string php 
Php :: validate time in laravel 
Php :: access storage from the view laravel 6 
Php :: how to get video duration in php 
Php :: php guzzle client x-www-form-urlencoded 
Php :: laravel pass view with data 
Php :: order by sum() laravel 
Php :: Problem 1 - phpspec/prophecy is locked to version 1.13.0 and an update of this package was not requested. - phpspec/prophecy 1.13.0 requires php ^7.2 || ~8.0, <8.1 - your php version (8.1.2) does not satisfy that requirement. 
Php :: laravel make model and controller 
Php :: run raw sql with doctrine manager 
Php :: add another field in existing migration laravel 
Php :: php remove 1 day from date 
Php :: wordpress get perma link 
Php :: How to fix undefined index: name in PackageManifest.php line 131 error with Composer 
Php :: laravel where condition on relationship 
Php :: laravel blade time difference 
Php :: how to run a specific migration in laravel 
Php :: display all custom post type ids 
Php :: get key by value array php 
Php :: laravel validate unique column 
Php :: php foreach mysql result 
Php :: get random data laravel 
Php :: symfony get query param 
Php :: pdo last id 
Php :: how to create new project in laravel 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =