0

I am trying to change the date so it appears at 2 days ago, or 30 minutes ago. I know I can use human time diff for this, but I don't know how to correctly add it to my site. Every time I try to add it I get a syntax error. I'm using the newspaper theme. I found the code that gets the date in my theme files, does anyone know how I can change the code so human time diff is included?

*This question isn't about why I was getting a syntax error. I know why, because I was adding in the code for human time diff wrong. I'm not the best at coding, which is why I'm asking for help to add it correctly.

code from theme

 function get_date($show_stars_on_review = true) {
        $visibility_class = '';
        if (td_util::get_option('tds_m_show_date') == 'hide') {
            $visibility_class = ' td-visibility-hidden';
        }

        $buffy = '';
        if ($this->is_review and $show_stars_on_review === true) {
            //if review show stars
            $buffy .= '<div class="entry-review-stars">';
            $buffy .=  td_review::render_stars($this->td_review);
            $buffy .= '</div>';

        } else {
            if (td_util::get_option('tds_m_show_date') != 'hide') {
                $td_article_date_unix = get_the_time('U', $this->post->ID);
                $buffy .= '<span class="td-post-date">';
                    $buffy .= '<time class="entry-date updated td-module-date' . $visibility_class . '" datetime="' . date(DATE_W3C, $td_article_date_unix) . '" >' . get_the_time(get_option('date_format'), $this->post->ID) . '</time>';
                $buffy .= '</span>';
            }
        }

        return $buffy;
    }
user6738171
  • 1,009
  • 2
  • 15
  • 50
  • What is the syntax error that you're getting? – Ryan Jul 19 '17 at 17:17
  • `$td_article_date_unix = get_the_time('U', current_time('timestamp' $this->post->ID));` your issue is on this line, a syntax-error where you have "*Unexpected variable*" error - you need some sort of separator before `$this->post->ID`.. But I don't understand exactly what you're trying to do there, because `get_the_time()` only has two arguments, and it makes no sense to pass the post-ID as the second argument for `current_time()` either. Consult the documentation for those WP functions. – Qirel Jul 19 '17 at 17:25
  • Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Qirel Jul 19 '17 at 17:25
  • If I try to add my echo date code into the code from the theme I get a syntax error saying there is an error in my code. I don't know how to correctly add the human time diff into my theme, so I just wanted to see if I could get some help with that. – user6738171 Jul 19 '17 at 17:31

1 Answers1

0

You can use date and strtotime to determine the date/time at any distance from the current date:

// 2 Hours from now    
date("Y-m-d H:i:s", strtotime('+2 hours'))

// 30 Minutes ago   
date("Y-m-d H:i:s", strtotime('-30 minutes'))

You can then change the date format to however you please.

Hope this helps

Draperaj
  • 36
  • 4