I am trying to get this weekend in php.
I get the current date by code:
$start_date = date("Y-m-d H:i:s", time());
How can I get the current weekend depending on the current date? Thank!
PHP strtotime function is magic, most people do not know, but you can do a lot with this function.
$start_date = date("Y-m-d H:i:s", strtotime('next Saturday'));
Use strtotime()
strtotime()
$sat = strtotime('saturday');
$start_date = date("Y-m-d H:i:s", strtotime('Saturday'));
:
<?php $time = mktime(); $found = false; while(!$found) { $d = date('N', $time); if($d == 6 || $d == 7) { $found = true; $weekend = date('d/m/Y G:i:s', $time); } $time += 86400; } echo("Weekend begins on: $weekend"); ?>
"" - , . PHP
$weekend = new DatePeriod( new DateTime('next Friday 18:00'), DateInterval::createFromDateString('+1 hour'), new DateTime('next Friday +2 day 23:59')); foreach($weekend as $hours) { echo $hours->format( "l Y-m-d H:i:s\n" ); }
-
if(date('w')==6){// Today is Saturday | Bugün Cumartesi ise $wknd=date("Y-md-").'-'.date("Y-m-d", strtotime('next Sunday')); }if(date('w')==0){// Today is Sunday | Bugün Pazar ise $wknd=date("Y-m-d"); }else{ // On weekdays | Hafta içi ise $wknd=date("Y-m-d", strtotime('next Saturday')).'-'.date("Ymd", strtotime('next Sunday')); } echo $wknd;
Source: https://habr.com/ru/post/1776173/More articles:Display image in GSP (Grails), get a link from a database - grailsJQuery Получить все теги с и показать их в- jqueryDjango Admin - sort by user method - djangovsjitdebugger.exe предлагает новые экземпляры, игнорируя уже запущенные - что делать? - debuggingProblem with batteries in prolog - prologRegex.Replace with compiled option in loop - c #нам нужно усечь большую таблицу перед тем, как ее сбросить? - oracleHow to make this tab animation with jquery? - jqueryHow to minimize the build time of a Flash project? - optimizationShould I start facebook application development now? - facebookAll Articles