Extension:DateDiff

MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
DateDiff
Release status: stable
Implementation Parser function
Description Takes two dates and returns all intermediary days
Author(s) Kwisatz, Jeroen De Dauw
Latest version 0.4.0 (2021-11-11)
MediaWiki 1.25+
PHP 7.2+
Database changes No
License Creative Commons Attribution Share Alike 3.0
Download
README
CHANGELOG
Example sandbox.semantic-mediawiki.org
Quarterly downloads 9 (Ranked 163rd)
Translate the DateDiff extension if it is available at translatewiki.net

The DateDiff extension adds the #dates parser function that returns a list of intermediary days.

UsageEdit

The #dates parser function comes with two parameters |StartDate and |EndDate which is used as follows:

Syntax
{{#dates:|StartDate=2016/10/01 |EndDate=2016/10/02 }}
Result

2016-10-01T00:00:00+02:00,2016-10-02T00:00:00+02:00

ExamplesEdit

A typical use case are events in a semantic setup that span multiple days. In order to have the events appear on all days on a calendar provided by the Semantic Result Formats extension, you would use something like (requires the ParserFunctions extension):

{{#ifeq: {{{recurring}}} |no |{{#set: Has date={{#dates:|StartDate={{{from}}} |EndDate={{{till}}} }} |+sep=, }} }}

Number of days between two days (requires the Arrays extension):

{{#arraydefine:days|{{#dates:|StartDate=2015-04-01 |EndDate=2015-04-10 }} }}
{{#arraysize:days}}

InstallationEdit

  • Download and place the file(s) in a directory called DateDiff in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php :
    wfLoadExtension( 'DateDiff' );
    
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.39 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension(). If you need to install this extension on these earlier versions (MediaWiki 1.39 and earlier), instead of wfLoadExtension( 'DateDiff' );, you need to use:

require_once "$IP/extensions/DateDiff/DateDiff.php";