Reputation: 649
I'm trying to show content in an specific date and time (in Wordpress), using :
if (!function_exists('isStreaming')):
function isStreaming()
{
date_default_timezone_set('America/Mexico_City');
$getDateNow = date('Y-m-d');
$getDayNow = date('Y-m-d', strtotime($getDateNow));
$DateBegin = date('Y-m-d', strtotime("2016-06-28"));
$DateEnd = date('Y-m-d', strtotime("2016-06-28"));
if (($getDayNow >= $DateBegin) && ($getDayNow <= $DateEnd) && is_home()) {
locate_template(array('/layouts/home/streaming.php'), true);
} else {
locate_template(array('/layouts/home/ad-top.php'), true);
}
}
endif;
That will Work, the content will show the whole day of the 28th of July.
But When I'm trying to add time aside the date it will only show me the content between the time range in any day, not respecting the date Variables.
I think I finally achieve what I wanted :D
<?php
if (!function_exists('isStreaming')):
function isStreaming()
{
date_default_timezone_set('America/Mexico_City');
$getDateNow = date('Y-m-d H:i');
$getDayNow = date('Y-m-d H:i', strtotime($getDateNow));
$DateBegin = date('Y-m-d H:i', strtotime("2016-06-27 08:00"));
$DateEnd = date('Y-m-d H:i', strtotime("2016-06-27 23:15"));
if (($getDayNow >= $DateBegin) && ($getDayNow <= $DateEnd) && is_home()) {
echo "YES $DateBegin";
} else {
echo "NO $getDayNow";
}
}
endif;
echo isStreaming();
?>
thanks for the ideas :D
Upvotes: 1
Views: 492
Reputation: 131
Well, just use time() and check the status of it.
$now = time();
$start = strtotime("2016-06-28");
$finish = strtotime("2016-06-29");
if($now >= $start AND $now < $finish){
locate_template(array('/layouts/home/streaming.php'), true);
} else {
locate_template(array('/layouts/home/ad-top.php'), true);
}
Upvotes: 1
Reputation: 10470
Please use DateTime:
$Now = new DateTime("now");
$DateBegin = new DateTime('2016-06-28'); //Add your time !
$DateEnd = new DateTime('2016-06-28'); //Add your time !
if($DateBegin <= $now && $DateEnd >= $now){
//is streaming ....
}
Upvotes: 0