Reputation: 9
I'm making a page that displays some info in a table and I want that table to have a darker background on the entries from the night time.
I'm thinking of something like:
if ( ($timestamp < strtotime('2012-02-16 20:00:00') && ($timestamp > strtotime('2012-02-16 08:00:00') ){}
But I want this to function 24/7 all year. How do I make the date any date (* - * - *) ?
Upvotes: 0
Views: 492
Reputation: 14489
Not sure what format $timestamp
is in, but if it's in Unix timestamp format (epoch seconds), you could do this:
$hour = date('H', $timestamp);
if ($hour >= 8 && $hour < 20)
If it's not in Unix timestamp format, perhaps you could make it so in your query, using the UNIX_TIMESTAMP()
function.
Upvotes: 4
Reputation: 120
Maybe you can format date with only hours component like
int(date('H', $timestamp ))
and test this value
Upvotes: 0
Reputation: 404
Use also can use mktime() function to make the timestamp.
For example, today, 8PM:
$mktime = mktime(20, 0, 0, date(n), date(j), date(Y));
Upvotes: 0
Reputation: 4882
$curtime = date('G', $timestamp);
if ($curtime >= 8 && $curtime <= 20)
{
//do whatever
}
I'd recommend reading up on date()
Upvotes: 1