2016-04-22 47 views
0

所以我試圖安排一個函數來調用每天/每週或每月。我有一個來自數據庫的當前日期(格式是'DD-MM-YYYY HH:mm',如果這很重要的話)。我想檢查當前日期是否恰好是該日期的一天/一週/一個月。我真的很新的PHP/laravel所以我不知道如何做到這一點,只是還沒有,因此沒有代碼:(。檢查當前日期是否爲指定日期的一天/一個月/一週php/laravel

的類型我的當前日期爲datetime

+0

沒有關於你的功能的更多信息以及它的調用方式很難說,但是我想你很難確保它總是在所討論的那天/每週/每月被調用和調用一次。爲什麼不使用cron或爲此任務設計的類似作業調度程序? –

回答

2

在PHP中,你可以通過檢查使用日期時間

$d1 = new DateTime(); 
$d2 = new DateTime(); 
$interval = $d2->diff($d1); 
echo $interval->y; // count if year between dates 
echo $interval->days; // count if days between dates 
0

任務調度Laravel> = 5.1 -
的Laravel調度命令,允許您使用容易理解PHP語法,只需要在一個cron項來管理任務執行的日期和時間您服務器。

您的任務計劃在app/Console/Kernel.php文件的計劃方法中定義。

當然,也有多種時間表可能會分配給你的任務:

Method      Description 
=================================================== 
->cron('* * * * * *');  Run the task on a custom Cron schedule 
->everyMinute();   Run the task every minute 
->everyFiveMinutes();  Run the task every five minutes 
->everyTenMinutes();  Run the task every ten minutes 
->everyThirtyMinutes();  Run the task every thirty minutes 
->hourly();     Run the task every hour 
->daily();     Run the task every day at midnight 
->dailyAt('13:00');   Run the task every day at 13:00 
->twiceDaily(1, 13);  Run the task daily at 1:00 & 13:00 
->weekly();     Run the task every week 
->monthly();    Run the task every month 
->yearly();     Run the task every year 

更多參考看到此鏈接 - https://laravel.com/docs/5.1/scheduling

希望這將幫助你!

相關問題