How to perform if statement for a certain timeperiod

99封情书 提交于 2020-01-06 17:36:39

问题


I want to perform certain tasks in PHP between Monday 10:00am till Saturday 10:00am and I want to perform other tasks between Saturday 10:30am till Monday 10am. Every week.

I am sorry if that's a silly question. Any help would be highly appreciated.


回答1:


if you are running a time triggered task run a cron job or if it is a user triggered like website and you want to change page according to day then use if else statement to select task.

you can get the time in weekday and hour:minute::second for if else selection using this

$d = new DateTime('Sunday,23:23:48 ');  //set time  day time format
echo $d->format('l , H:i:s ');

$date = new DateTime();   // get current datetime

echo $date->format('l , H:i:s ');   //php get time in day time format

//output example  Sunday , 23:23:48 Sunday , 23:34:47



回答2:


$currentTime = time();
$time = date('H:i',$currentTime);  
$date = date('h:i:s a', time());
$timestamp = strtotime($date);
$day = date('D', $timestamp);


if ( ( ($day == "Sat") && ($time < 11) ) || ($day == "Mon" && $time > 9) )

{
     # weekday then truncate table
}


来源:https://stackoverflow.com/questions/42475435/how-to-perform-if-statement-for-a-certain-timeperiod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!