How to Find the Difference Between Dates

Below you will find how to use one of the handy functions available to developers who need to customize InetSoft's business intelligence application. The average business user will never need to use functions since all their data exploration is possible via simple pointing and clicking of an interactive dashboard.

But enterprise and cloud application developers will find any kind of data transformation is possible so that whatever metric or functionality is desired is possible on the fly without having to have the data pre-calculated in a data warehouse, for instance.

The Start Free button above gives you two options for using InetSoft's free dashboard visualization software.

#1 Ranking: Read how InetSoft was rated #1 for user adoption in G2's user survey-based index Read More

Useful Date Functions

This section discusses several basic date functions: computing the difference between dates, computing a date in the past or future, formatting a date, and extracting date components.

Finding the Difference Between Dates

Use the 'dateDiff()' function to find the difference between two dates in terms of days, months, or years.

dateDiff('d', fromDate, toDate);    // days
dateDiff('m', fromDate, toDate);    // months
dateDiff('yyyy', fromDate, toDate); // years

For example, if a table displays the column 'Birth Date', you can create a formula column to calculate the current age of an individual by subtracting the 'Birth Date' from today's date:

dateDiff('yyyy', field['Birth Date'], CALC.today())

Calculating a Past or Future Date

Use the 'dateAdd()' function to find a date which is n units (days, months, or years) into the past or future.

// 1 day before today
dateAdd('d', -1, CALC.today());
 
// 5 months after today
dateAdd('m', 5, CALC.today());
 
// 3 years before Order Date

dateAdd('yyyy', -3, field['Order Date']);

For example, consider a query 'Order Bookings' that accepts two date parameters, 'StartDate' and 'EndDate'. Assume you want the query to return data from the date range of 15 days before today's date until 15 days after today's date. Use the dateAdd() function to obtain these dates as follows:

var sd = dateAdd('d', -15, CALC.today());
var ed = dateAdd('d', 15, CALC.today());
var q = runQuery('Order Bookings',
        [['StartDate', sd], ['EndDate', ed]]);

Extracting a Date Component

The CALC library provides a number of functions to extract different components of a date object: year, month, day, quarter, etc.

// extract the current date and time
var todDate = CALC.today(); //e.g., Feb-21-2007


// extract the year
var y = CALC.year(todDate); // 2007


// extract the quarter
var q = CALC.quarter(todDate); // 1
 
// extract the day of the week
var dow = CALC.weekdayname(todDate); // Wednesday
 
// extract the date

var d = CALC.day(todDate); // 21
 
// extract the month
var m = CALC.month(todDate); // 2

Formatting a Date

Use the 'formatDate()' function to format a Date field. For example:

// Get today's date, e.g., Thur Oct 01 16:54:22 EDT 2009
var d = CALC.today();
 
// Format as "Today Is: 10/01/09"
Text1.text = 'Today Is: ' + formatDate(d, 'MM/dd/yy');

More Articles About Dashboarding

Assortment of Great Business Intelligence Examples - Are you looking for great business intelligence examples? InetSoft has published an extensive library of fully-functional examples of data discovery and interactive reporting. InetSoft is top-rated by users on G2 Crowd. Interact with examples and register for a personalized demo. This supply chain analysis example gives a global view of shipped orders. This view is aided by several map charts, one of which features a zoom in on key areas. Key metrics featured are Perfect Orders, Shipping Cost by Country, Average Shelf Time by Product, Stocked vs. Made to Order, and Made to Order Planned vs Actual Time...

Collection of More Mobile BI Dashboard Examples - Below are some business visualization examples to give you a look at some of the advanced displays that can be created using Style Intelligence. Style Intelligence can be used to build visualizations for any type of department or industry. These visualizations can be built by nontechnical users with a basic Excel level understanding of data. This mobile product return analysis dashboard highlights how a dashboard can incorporate many different pastel shades and not be overwhelming. This allows color to be used as an additional dimension on both dashboard charts. Tapping any of the colored data points with a finger reveals which categories are signified by which colors...

Data Request Process - The first component of a data governance dashboard is a data request process. Users should be able to easily request new reports and dashboards, as well as update and enhance current ones, thanks to this approach. Regardless of their level of technical skill, it should be simple to use and available to all stakeholders. Organizations can guarantee that reports and dashboards are accurate and up-to-date while reducing the chance of mistakes or inconsistencies by offering a simple and straightforward approach for obtaining data...

Evaluate InetSoft's Highly Rated Reporting Tools - Are you looking for a highly rated reporting tool? Since 1996 InetSoft has been delivering easy, agile, and robust business intelligence software that makes it possible for organizations and solution providers of all sizes to deploy or embed full-featured business intelligence solutions. View a demo and try interactive examples. InetSoft's comprehensive reporting platform can be used to create over 30 chart styles including bar, pie, line, curve, radar, waterfall, speedometer, pareto, candle, stock, stick, and bubble. These charts can be customized to show targets, provide desired x/y-axis formats and intervals, and even to show multiple datasets...

Finance Data Consolidation and Mashup - The finance department interacts with many areas. Consolidating data from various systems and departments can be a very challenging task. This often is the source of spreadsheet hell that breaks data lineage and causes inconsistent reporting. InetSoft's data mashup technology is an elegant solution. Data mashup is designed for business analysts. With rich connections to enterprise software data sources, business analysts can further mix in Excel data to do tasks such as experimenting with forecasted model data...

Happy Analytics Dashboard Customers - InetSoft solutions have been deployed at over 5,000 organizations worldwide, including 25% of Fortune 500 companies, spanning all types of industries. Here are some testimonials from some of our InetSoft customers: "One of the advantages of this tool is that we started using it from the very beginning without major changes in the extracted data. Using Style Scope from InetSoft gave us the ability to provide a graphical representation of the key data to top management right 'out-of-the-box' and move from static tables of numbers to charts and graphics that are much easier to understand. Before the use of Style Scope, it took us months to build KPI dashboards that were simple enough to manage by end-users; now in a couple of days we can customize several graphic views, and even the users can build their own reports without IT intervention. With InetSoft...

Long List of Marketing Campaign Metrics - Impressions: The number of times your ad or content is displayed to potential customers. Clicks: The number of times someone clicks on your ad or content. Click-through rate (CTR): The percentage of people who click on your ad or content after seeing it. Cost-per-click (CPC): The average cost you pay for each click on your ad. Cost-per-impression (CPM): The cost you pay for every 1,000 impressions of your ad...

Many Top Reporting Software Examples - Searching for the top reporting software examples? InetSoft provides examples from its highly-rated, easy to use dashboard reporting software. This supply chain reporting example delivers the most important global shipping aggregates in one easy-to-read report. A spotlight effect on one of the map charts highlights the location of some of the biggest shipment locations. This utility report gives updates on power usage as well as various maintenance priorities that concern anyone maintaining a power grid. Color is used to visualize extra dimensions throughout, enabling more to be reported on less charts...

Volunteer Recruitment and Retention - Attracting and keeping volunteers is a primary goal of any volunteer management dashboard. Metrics including the quantity of new volunteers recruited in a given period of time, the retention rate, and the efficiency of the recruiting process are all monitored under this KPI. Administrators may swiftly evaluate the effectiveness of recruiting efforts, spot patterns, and improve their methods by using data-driven decision-making made possible by visual depiction via charts. Organizations may develop focused retention campaigns and improve volunteer onboarding procedures by closely monitoring these KPIs in order to develop a committed and long-lasting volunteer base...

Previous: Adding Tooltips to a Table or Chart