This plugin is used to calculate the numbers of days, months, or years between two dates just like datedif function in Microsoft Excel. You can use it to display your age dinamically, how long your blog has been online, or other events counter based on the dates.
Download
Click here to download datediff.zip.
Installation
- Put the file "datediff.php" from extracted datediff.zip in your plugins folder. This is located at /wp-content/plugins/.
- Go to the Plugins page in your WP Administration.
- Activate Datediff plugin.
- That's all, Datediff plugin is installed.
Usage
Now you have to choose where you want to use this date calculation on your blog. I suggest putting it wherever outside your post template such as sidebar, header, or footer. Then place this snippet:
-
<?php datediff(start_date, end_date, unit); ?>
start_date is a date represents starting date of the period.
end_date is a date represents ending date of the period, default "now".
The dates may be entered a string containing a US English date format according to the GNU Date Input Formats syntax. Some valid value are "2005-08-24", "24 August 2005", "now", "tomorrow", "now +7 hours", or "next Thursday".
unit is the type of information you want returned as explained below:
| unit | Returns |
| "Y" | The number of complete years in the period. |
| "M" | The number of complete months in the period. |
| "D" | The number of complete days in the period. |
| "MD" | The difference between the days in start_date and end_date. The months and years of the dates are ignored. |
| "YM" | The difference between the months in start_date and end_date. The days and years of the dates are ignored. |
| "YD" | The difference between the days in start_date and end_date. The years of the dates are ignored. |
The default value for unit is "D".
Examples
-
I have my birthday on next <?php datediff("2005-9-22"); ?> days.
output:
I have my birthday on next 27 days.
-
I am <?php datediff("1980-8-26","now","y"); ?> years old.
output:
I am 25 years old.
-
This blog have been online for
-
<?php datediff("2005-7-18","now","y"); ?> years,
-
<?php datediff("2005-7-18","now","ym"); ?> months
-
and <?php datediff("2005-7-18","now","md"); ?> days.
output:
This blog has been online for 0 years, 1 months and 10 days.











TY
I put it in my Blog.
Rob