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


If DatePicker date is less than 1 year old

    • Trishah

    • October 7, 2019 at 11:44 am

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

        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>
        else :
            // no rows found

    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.

    • vverner

    • October 8, 2019 at 7:12 am

    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) :
    • Trishah

    • October 8, 2019 at 8:32 am

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.