This plugin shows the number of days between now and the first day you published an entry.
It’s free to use for anyone, have fun.
Instructions:
- Copy text below into a blank text file named days_old.php (using Notepad or SimpleText)
- Upload that text file to your plugins directory (usually wp-content/plugins)
- Activate it under Plugins in your admin
- Call it from a template by inserting the line:
<?php days_since_birth(); ?>
This will give you a number which is the number of days between now and when your first post was published.
function days_since_birth() {
global $wpdb;
$now = gmdate(“Y-m-d H:i:s”,time());
$first_post = $wpdb->get_results(“SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_date < '$now' ORDER BY post_date ASC Limit 1");
if ($first_post) {
foreach ($first_post as $post) {
$first_day=strtotime($post->post_date_gmt);
$now=strtotime($now);
//Then you subtract the lower date from the higher.
$between = $now – $first_day;
//Finally your divide the result by the number of seconds on a day.
$days_old = $between / (24*3600);
}
} else {
$days_old=0;
}
echo round($days_old);
}
?>
I do not provide support of any kind for this script.



24 comments
January 16, 2006 at 2:46 pm
Pingback from 42: Life, the Universe and Blogging
October 30, 2006 at 6:59 pm
Pingback from TroubleZone.Net Blog Archive » On towards the wilderness..
December 13, 2005 at 7:36 pm
Ravi U
Very nice for those of us with no knowledge of PHP/WordPress
. Just one thing though…might want to take off those couple spaces at the end of the code as it can lead to problems when activating the plugin (applies to any plugin, actually). Other than that, great!
December 17, 2005 at 11:36 am
Martin
Hmm when i upload days_old.php to my plugin folder and activate it all i get is a white page, nothing works and when i delete the file from the server everything works again, do you know what the problem is?
December 18, 2005 at 12:15 am
cheekyboots
Not really. Check that you uploaded it as ASCII and not binary, that there are no spaces or linebreaks where there shouldn’t be.
December 18, 2005 at 4:22 am
Martin
Thank you but it doesnt work. The page turns blank/white when i upload it and clicking on Site admin or whatever i do its blank. I have no spaces or linebreaks in the code and i uploaded it in ASCII. I’m gonna look deeper in this.
December 30, 2005 at 9:30 am
vally
It makes it at my site too…
January 16, 2006 at 2:17 pm
Becca
Great plugin
As my blog was nearly a year old, I thought I’d edit the plugin a bit to display years as well. For blogs under a year old, it displays “days old”, but for blogs that are over a year old, it displays the number of years as well, with an ‘s’ if there is more than one year. If it is exactly on the year (365 days old = 1 year old, 730 days old = 2 years old), it doesn’t display days. The link right below is the link to the edited plugin.
http://www.breakfastclubber.com/files/days_and_years_old.txt
January 31, 2006 at 9:03 pm
Serge Norguard
Fatal error: Call to undefined function: days_old() in /../../footer.php on line 18
line 18 =
March 7, 2006 at 6:28 am
Scott Grayban
Linux users will need to change the line
$now = gmdate(”Y-m-d H:i:s”,time());
to
$now = gmdate(‘Y-m-d H:i:s’,time());
For this to work.
March 7, 2006 at 8:06 am
Scott Grayban
This works for us linux users instead.
[code]
$now = gmdate('Y-m-d H:i:s',time());
$first_post = $wpdb->get_results("SELECT post_date_gmt FROM `$wpdb->posts` WHERE `post_status` = 'publish' AND post_date days old.
March 7, 2006 at 8:07 am
Scott Grayban
Uggg it didn’t work
Just contact me from my blog and I’ll email you back with what works for me.
April 19, 2006 at 3:19 am
cheekyboots
Hmm. I’m using Linux, and the code I presented works on my server. Could be your specific variety of Linux, or something else.
May 26, 2006 at 10:28 am
Marcos
There was a problem with quotes. WordPress makes more fancy the code, changing characters. It would be a better idea offering a .php or .txt file for downloading.
These are the lines that worked for me:
$now = gmdate(“Y-m-d H:i:s”, time());
$first_post = $wpdb->get_results(“SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_date
July 10, 2006 at 11:45 am
Jeroen
I’ve got the same problem. As soon as i activate the plugin, everything turns blank! Is this plugin WP2-compatible?
July 10, 2006 at 11:53 am
cheekyboots
Yes – I am running 2.0 and I use the plugin.
August 15, 2006 at 12:59 am
Babz
I had the same problem with installing and getting an error message once the plugin was uploaded.
I think the problem is coming from copy and pasting it into the text form.
In my situation I was seeing blocks instead of ” When I corrected that it worked. So if you are copy then pasting the code check it before installing.
Great Plugin by the way! Love it
November 24, 2006 at 9:18 am
Nikolay
The problem is the curly quotes in the code:
It should contain only straight, ASCII single and double quotes, no inverted commas:
December 9, 2006 at 12:49 am
Steinar
Thanks, Emma, nice plugin.
I put the file here if anyone’s interested http://foynland.org/files/days_old.rar
January 23, 2007 at 6:42 am
Annica
This plugin doesn’t work with the new version of wordpress. Care to update?
January 23, 2007 at 11:48 am
cheekyboots
I’m using WP 2.1-alpha1 and it works fine. If I ever upgrade and it breaks, I’ll fix it, otherwise not likely.
January 23, 2007 at 12:50 pm
theddy
Hi
Version 1.0 of your plugin seems not to be compatible with WP 2.1 – the day count is wrong.
Thanks.
January 25, 2007 at 11:46 am
Jen
This plugin doesn’t work with 2.1, I was using it when I installed the new version (followed the instructions and deactivated it of course), and when I activated it again it said that my blog had been up for 2611 days (in reality it has only been up for 22 days)…
January 25, 2007 at 11:55 am
cheekyboots
It works for me, must be something else going on. However, it is a very very simple script and I’m sure you can either fix it or make your own. I’m closing the comments on this post. Use the script if you want or don’t if you want. I’m not interested in supporting it.