Jump to content

time function, do some time at a certian time


Orionsbelter

Recommended Posts

You'd have more luck with the date() function because there are an infinite amount of times in which it is midnight.

 

<?php
if(date("G") == "0") 
{
echo "it's midnight";
}
?>

 

and so on..

 

P.s. not that it matters, but strictly speaking 12.00pm is midday lol. 12.00am is midnight.

Link to comment
Share on other sites

You're better off using a switch/case if you want to have lots of different messages.

 

<?php
switch(date("G"))
{
   case "7":
   echo "It is 7.00am";
   break;

   case "12":
   echo "It is 12.00pm - Midday : ]";
   break;

   case "0":
   echo "It is midnight!";
   break;

   default:
   echo "This will display if the date function returns a value that hasn't been dealt with previously";
   break;
}
?>

 

Orr... if you really want to stick to the if .. else.. method..

 

<?php
if(date("G") == "0")
{
   echo "it is midnight";
} 
elseif(date("G") == "7")
{
    echo "it is 7.00am";
}
elseif(date("G") == "[YOUR TIME HERE]")
{
   echo "...";
}
else
{
   echo "This will display if the date function returns a value that hasn't been dealt with previously";
}
?>

 

It works on a twenty four hour clock, you just simply change the numbers "0" or "7" to whatever time you want on a twenty four hour clock

 

To schlo_50:

 

No, because the date output is not in the format HH:MM.  It simply returns H in 24 hour clock format.. you can however change the date function's parameters to produce such an output if you wished and then do it like that though.

Link to comment
Share on other sites

Would this not do?

 

<?php

$current_time = date('G');

if($current_time == "19:00") {

print "It's 7:00pm.";

}

?>

 

It doesn't return it as 19:00, it just returns it as 19.

 

As ProjectFear says though, making a script work without someone accessing it would be trickier..

Not necessarily, read up on it. It can be quite handy.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.