Support

Account

Home Forums Front-end Issues Show text after date gone

Solved

Show text after date gone

  • Hello,
    I am here to ask that I created a date picker field with name of the Last Date. Is it possible that when date passed it will show text and hide the date?

  • Any help, 1 week gone.

  • You did not really give a lot to go on, but yes, it would be possible.

    You get the value, you compare it to the current date and do something based on the comparison.

    
    $today = date('Ymd');
    $date = get_field('date_field', false, false); // get unformatted value
    if ($date < $today) {
      // date is passed
    } else {
      // date is not passed
    }
    
  • Actually, I am using ACF and I create a date field with the name of (LAST DATE). So I just want to show a specific text after or replace the field.

    For Example, I added the last date 15 Dec 2019 and it’s showing me on my site. When 15 Dec 2019 gone then it will show like this.

    Replace The date: Job Expire

  • Ok I fixed it, thanks.

    $currentdate = new DateTime();
    $date = get_field('last_date', false, false);
    $date = new DateTime($date);
    if ($currentdate > $date) {
      echo '(Job Expire)';  
    } else {
      echo get_field( 'last_date' );
    }
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Show text after date gone’ is closed to new replies.