I want to calculate the difference between post's publishing time and current time, and I want to read that value as a number (number of hours, minutes, seconds whatever, i just want it to be a number).
The reason is I want to do something depending on the post's age.
Would this code work?
$date = get_post_time('G', true, $post);
$current_time = current_time( 'mysql', $gmt = 0 );
$newer_date = strtotime( $current_time );
$postsage = $newer_date - $date;
if($postsage < 7200){
...
}
// if post is between one and two hours old
else if (($postsage >= 7200) && ($postsage <=14400)){
...
}
else {
...
}
Is this code bit valid?