Check php date and time

Asked

Viewed 54 times

-2

My doubt is how to query date and time with an IF to manipulate a php script on schedule and scheduled day.

I came to do so at first it worked more I know what went wrong after. In the example below would run every Saturday half day,

if(date('D') == 'Sat' AND date('H:i') == '12:00') {
  echo"Isso é um teste";
}

  • This will only be executed if it is 12:00, any delay will make it not run. I, very sense this build. First, that Mysql already has a resource for that which is the MySQL Scheduled Event (not to confuse Events with Triggers). Second, that this could be done implicitly when the "player" requests the information, if you have the date of the "quest" and verify that it was done before this current week, then it must be "generated a new quest" (if this is the purpose of the code, just deducing).

  • In the thesis it was to be able to manipulate the query by php. ?

  • I enabled in mysql SET GLOBAL event_scheduler = ON; However I can’t get Event to do it every Saturday noon.

  • Failed to declare the date_default_timezone_set('America/Sao_Paulo'); Thank you.

1 answer

1

That way as you wrote the code, the script will only work if it runs exactly on Saturday at noon, note that someone will have to manually execute it at exactly this time.

If your intention is that it runs automatically every Saturday at noon you will have to do this through the server using CRON.

Here’s a more detailed answer about what CRON is and how to use it: What are CRON JOBS and how to use them with PHP

Browser other questions tagged

You are not signed in. Login or sign up in order to post.