Forums

Checking against the post date/time (2 posts)

  1. kreativjustin
    Member
    Posted 1 year ago #

    I'm trying to check against the post date, say back to 2 days or 48 hours.

    I know you display the date via this code.

    <?php the_time('j F Y') ?>

    and it will print out 29 March 2011 or whatever the date would be

    So I'm wondering how you'd strip it down to check if it's two days old.

    Appreciate the help.

  2. kreativjustin
    Member
    Posted 1 year ago #

    Well I took a leap on my own and came up with this

    function wemagazine_datecheck() {
    	$post_date = the_date('Ymd','','',FALSE);
    	// We gathered original date from the post, let's strip it down so we can use it
    
    	$post_year = substr($post_date,0,4); // Years stripped. 0 from left, 4 chars max
    	$post_month = substr($post_date,4,2); // Months stripped. 5 from left, 2 chars max
    	$post_day = substr($post_date,6,2); // Months stripped. 7 from left, 2 chars max
    
    	// Now we need to gather info for the current date.
    	$current_date = date('Ymd');
    	// Great, let's strip down the current date. We can just copy, paste, modify the top one!
    
    	$current_year = substr($current_date,0,4); // Years stripped. 0 from left, 4 chars max
    	$current_month = substr($current_date,4,2); // Months stripped. 5 from left, 2 chars max
    	$current_day = substr($current_date,6,2); // Months stripped. 7 from left, 2 chars max
    
    	// Let's turn them into usable strings
    	$post_usage = $post_year . $post_month . $post_day;
    	$current_usage = $current_year. $current_month . $current_day;
    
    	$difference = $current_usage-$post_usage;
    
    	echo $difference;
    
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic