Chris Cummings
Chris Cummings

Reputation: 1548

Show something at a specific time each week using PHP

Using PHP, I have a DIV I need to show each week on Thursday from 7pm to 8pm (server time, not user time). I'm thinking I need something with mktime here but I'm not sure how to make sure it does it each week at the same day/time interval.

Any thoughts?

Upvotes: 0

Views: 325

Answers (4)

zaf
zaf

Reputation: 23244

Simply use the date function with the correct parameters to check the time frame you want. For example:

if(date('N')==4)...   // Thursday

if(date('G')==19)...  // its 7.?? PM

etc.

or the fancy:

if(date('NG')=='419'){...}

Upvotes: 2

Nick
Nick

Reputation: 6346

A simple if statement:

<?php
if (date('w')==4 && date('G') == 19) {
 // do stuff here
}

This would activate on Thursday at 19:00 and deactivate as soon as it hits 20:00

Upvotes: 2

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385174

if (date("D") == "Thu" && date("H") == 19) {
   echo $yourDiv;
}

Next time please show us what you tried, then ask a question about a programming language! This isn't http://make-it-for-me.com

Upvotes: 2

Timothy Aaron
Timothy Aaron

Reputation: 3078

if( date('l') == "Thursday" && date('G') == 19 )
{
    // do something
}

Upvotes: 2

Related Questions