Support

Account

Home Forums General Issues If DatePicker date is less than 1 year old

Solved

If DatePicker date is less than 1 year old

  • I am showing uploaded files in a repeater field with the following code:

    <ol>
    <?php
        if( have_rows('train') ):
          while ( have_rows('train') ) : the_row();
            $file = get_sub_field('file_upload');
            $title = $file["title"];
            $url = $file["url"];
            $date =  get_sub_field('file_date');
            $ext = pathinfo($url, PATHINFO_EXTENSION);
            if( $file ) { ?>
              <li><a href="<?php echo $url; ?>"><?php echo $title; ?></a> <span class="type">(<?php echo $ext; ?>)</span> <span class="date"><?php echo $date; ?></span> <span class="age"> ??? </span></li>
            <?php
            }
         endwhile;
        else :
            // no rows found
        endif;
    ?>
    </ol>

    The $date shows a date like: “03/29/2015” for March 29, 2015.

    I’d like to show “New” for the age of the document if DatePicker date is no more than 1 year old.

  • Hey Trishah,

    You just need to use a conditional on your loop, something like that:

    
    $date = date( "U" , strtotime( get_sub_field('file_date')));
    $new = date("U") - 1538943104;
    if($date < $new) :
       [....]
    endif;
  • Ah! Thank you. That helped me figure it out. Here is my solution to show a dot if file is less than 6 months old:

    
    $age = strtotime( get_sub_field('file_date'));
    $now = strtotime("now");
    
    <span class="age"><?php if ($now - $age < 15778800) { echo "<i class='fas fa-circle'></i>"; }?></span>
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘If DatePicker date is less than 1 year old’ is closed to new replies.