简体   繁体   中英

How to subtract days from Laravel command scheduler?

I need to run a command that creates database table each year quarter, and I found this command

$schedule->command('test:create-table table_test')->quarterly();

But I want to run this command a week before, just to be sure that the table already created before I start insert data into it.

what is the best way to achieve that?

Thanks in advanced

I think this will help you: $schedule->command('test')->yearlyOn(12, 24, 0);

the first value 12 is the month its the december and the 24 is the day its one before the year is over. The last value ist the time its on 0 a clock!

This is for one week before a year ends. but you need quarterly you can also use CRON

Under the hood, Laravel implements "quarterly" as the first day of every quarter at 00:00 with the cron statement 0 0 1 1-12/3 *

While there isn't a built-in "weekBefore" method, there is a cron() method, and you can get fairly close by picking, for example, the 24th day of particular months in a single cron statement. Eg:

// Run on the 24th of Mar, Jun, Sept, and Dec
$schedule->command('foo')->cron('0 0 24 3,6,9,12 *');

If you wanted to be exactly the week before, you'd have to break it up into at least two statements (because Mar & Dec have 31 days, while Jun & Sep have 30).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM