Wordpress, How Many Days Old is the Post

Michael Gray

By Michael Gray
In Programming  

Print Post Print Post Email Post Email Post    ADD TO STUMBLEUPON Sphinn It ADD TO DEL.ICIO.US  Tweet This

Over on Performancing.com Andy, says the money is in the archives, stupid. Nick talks about Monetizing your Blog, by showing different levels of advertising based on how old post is and whether someone is logged in or not. Now Andy’s doing a blog monetization makeover, and time sensitive ads came up again. Since I’ve got the hood open on this WordPress install I figured I would work up some code to figure out how old a post is.


$postdate = str_replace("-", " ",substr($post->post_date, 0,10));
$postd = explode(" ", $postdate);
$ageunix = (( time() - mktime('','','', $postd[1], $postd[2], $postd[0])));
$days_old = floor($ageunix/(24*60*60));

Basically what I’m doing is getting time and date of the post. I then isolate the just date and remove out “-” characters. I explode it into an array, convert them to unixtime, and do the subtraction. Then convert it back from UNIX time to days old expressed as an integer value (my high school math teacher Sister Miriam would be proud).

Related posts:

  1. Wordpress SEO: Wordpress Security Why it Matters to SEO In recent weeks wordpress security, or more correctly the lack...
  2. How to Use Evernote to Create the Ultimate Post Conference Reference Guide Now that Pubcon is over I’m going to let you...
  3. Wordpress SEO: How to Choose a Permalink Structure For this post we’re going to be taking  look at...

Crazyegg Link Tracking

{ 7 comments }

Ozh December 15, 2005 at 2:49 am

Spare yourself a few lines of code :


$ageunix = time() – get_the_time(’U');
$days_old = floor($ageunix/(24*60*60));

(on a side note, your captcha system is way too annoying… Had to try 3 times to get this comment posted. There are many WP plugins less intrusive and as effective)

Administrator December 15, 2005 at 8:16 pm

I tried that wasn’t working on my dev server for some reason, but it works on the live one, go figure.

Cal December 16, 2005 at 4:03 am

Well you can otherwise spare a line by not replacing the dashes with spaces. Just perform the explode on the dash.

Does wordpress not have an accountsystem? I have to add my name and email etc again everytime I post.

Administrator December 16, 2005 at 7:28 am

Does wordpress not have an accountsystem? I have to add my name and email etc again everytime I post.

Sure it has an accountant system, didn’t you get your password? ;-)

Cal December 16, 2005 at 8:11 am

*hits head on desk*

Squid June 22, 2007 at 8:46 am

I’m glad wordpress has sorted all this out now. It’s like you had to be a genius to work this out. Lucky for us now.

Nancy S September 20, 2007 at 10:29 pm

Wow. You gys must have been pioneers or something. Wordpress is so easy to use these days.

Comments on this entry are closed.