Jump to content

Show text between two dates?


Roych
 Share

Recommended Posts

Hello,

I'm working on a event calendar and so far everything works fine. But I would like to show some text (Still ongoing!) if an event last more than one day. 

right now I have a text for events that starts today, but would be great if I could implement this also.

Im using this to show TODAY text for my events. I have two datetime fields caled (Start_date and End_date) for start and end of events (normal not publish_from & until).

<?php if (date('d-m-Y') == date('d-m-Y', $single->getUnformatted('Start_date'))) : ?>
	<div class='Danes-text'>TODAY!</div>
<?php endif; ?>

I would like to somehow combine this with events that last more than one day.

I'm not good with php so I need your help.

I was playing with the code below, but not sure what I'm doing here ... ?

<?php
$startDate = date('d-m-Y');
$startDate=date('d-m-Y', $single->Start_date);
//echo $startDate; // echos today! 
$eventDateBegin = date('d-m-Y', $single->Start_date);
$eventDateEnd = date('d-m-Y', $single->End_date);

if (($startDate > $eventDateBegin) && ($startDate < $eventDateEnd)){
    echo "is between";
}else{
    echo "NO GO!";  
}
?>

I hope u understand what I mean.

Thank you

R

Link to comment
Share on other sites

if(
  date('Ymd') >= date('Ymd', $single->getUnformatted('Start_date')) AND
  date('Ymd') <= date('Ymd', $single->getUnformatted('End_date'))
  ) {
  echo "<div class='Dates-text'>ONGOING!</div>";
}

...if it is enough to compare the date (ignoring current time).

Link to comment
Share on other sites

2 minutes ago, bernhard said:

if(
  date('Ymd') >= date('Ymd', $single->getUnformatted('Start_date')) AND
  date('Ymd') <= date('Ymd', $single->getUnformatted('End_date'))
  ) {
  echo "<div class='Dates-text'>ONGOING!</div>";
}

...if it is enough to compare the date (ignoring current time).

that was fast ? It works, is this maybe possible to combine this with the TODAY also? So if event is only one day it would say TODAY if more than one day ONGOING but the first day would stil say Today.

Thank you

R

Link to comment
Share on other sites

Ok i think I got it if there is something wrong, please correct me. Im just postponing this one for one day. Im using the today code wich is gone the second day and next day this one shows.

first day:

<?php if (date('d-m-Y') == date('d-m-Y', $single->getUnformatted('Start_date'))) : ?>
	<div class='Danes-text'>TODAY!</div>
<?php endif; ?>

Next day:

<?php
if(
  date('Ymd', time() + 86400) >= date('Ymd', $single->getUnformatted('Start_date')) AND
  date('Ymd', time() + 86400) <= date('Ymd', $single->getUnformatted('End_date'))
  ) {
  echo "<div class='Dates-text'>ONGOING!</div>";
}
?>

it looks like it is working on my test events. ?

R

Link to comment
Share on other sites

$today = date('Ymd');
$start = date('Ymd', $single->getUnformatted('Start_date'));
$end = date('Ymd', $single->getUnformatted('End_date'));
if($today == $start AND $today == $end) echo "<div class='Dates-text'>TODAY!</div>";
elseif($today >= $start AND $today <= $end) echo "<div class='Dates-text'>ONGOING!</div>";

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...