Get Free Trial
  1. API reference
  2. Welcome
    1. Getting started
    2. Get Flexmonster
    3. Quick start
    4. System requirements
    5. Troubleshooting
    6. Managing license keys
    7. Migrating from WebDataRocks to Flexmonster
  3. Integration with frameworks
    1. Available tutorials
    2. Integration with Angular
    3. Integration with React
    4. Integration with Vue
    5. Other integrations
      1. Integration with Python
        1. Integration with Django
        2. Integration with Jupyter Notebook
      2. Integration with React Native
      3. Integration with Blazor
      4. Integration with AngularJS (v1.x)
      5. Integration with TypeScript
      6. Integration with R Shiny
      7. Integration with jQuery
      8. Integration with Ionic
      9. Integration with Electron.js
      10. Integration with Webpack
      11. Integration with RequireJS
  4. Connecting to Data Source
    1. Supported data sources
    2. JSON
      1. Connecting to JSON
      2. Connecting to JSON using Flexmonster Data Server
      3. Data types in JSON
    3. CSV
      1. Connecting to CSV
      2. Connecting to CSV using Flexmonster Data Server
      3. Data types in CSV
    4. Database
      1. Connecting to SQL databases
      2. Connecting to a MySQL database
      3. Connecting to a Microsoft SQL Server database
      4. Connecting to a PostgreSQL database
      5. Connecting to an Oracle database
    5. Flexmonster Data Server
      1. Introduction to Flexmonster Data Server
      2. Getting started with Flexmonster Data Server
      3. Flexmonster Admin Panel Guide
      4. Data sources guide
      5. Security and authorization guide
      6. The Data Server as a DLL
        1. Getting started with the Data Server as a DLL
        2. Referencing the Data Server as a DLL
        3. Implementing the API controller
        4. Implementing the server filter
        5. Implementing the custom parser
        6. DLL configurations reference
        7. The controller's methods for request handling
      7. The Data Server as a console application
        1. Installing the Data Server as a console application
        2. Configurations reference
        3. Data sources guide
        4. Security and authorization guide
      8. Troubleshooting the Data Server
    6. MongoDB
      1. Introduction to Flexmonster MongoDB Connector
      2. Getting started with the MongoDB Connector
      3. Embedding the MongoDB Connector into the server
      4. Configuring the MongoDB Connector
    7. Microsoft Analysis Services
      1. Connecting to Microsoft Analysis Services
      2. Getting started with Flexmonster Accelerator
      3. Referencing the Accelerator as a DLL
      4. Configuring the authentication process
      5. Configuring a secure HTTPS connection
      6. Troubleshooting
    8. Custom data source API
      1. Introduction to the custom data source API
      2. A quick overview of a sample Node.js server
      3. A quick overview of a sample .NET Core server
      4. Implement your own server
        1. Implementing the custom data source API server
        2. Implementing filters
        3. Supporting more aggregation functions
        4. Supporting multilevel hierarchies
        5. Returning data for the drill-through view
        6. Testing your custom data source API server
    9. Elasticsearch
      1. Connecting to Elasticsearch
      2. Configuring the mapping
    10. Pentaho Mondrian
      1. Connecting to Pentaho Mondrian
      2. Getting started with the Accelerator
      3. Configuring Mondrian roles
      4. Configuring username/password protection
      5. Configuring a secure HTTPS connection
      6. Troubleshooting
    11. Connecting to other data sources
  5. Accessibility
    1. Accessibility overview
    2. Keyboard navigation
  6. Configuring report
    1. What is a report
    2. Data source
    3. Slice
    4. Options
    5. Mapping
    6. Number formatting
    7. Conditional formatting
    8. Set the report for the component
    9. Get the report from the component
    10. Share the report
    11. Date and time formatting
    12. Configuring global options
    13. Export and print
    14. Calculated values
    15. Custom sorting
  7. Charts
    1. Available tutorials
    2. Flexmonster Pivot Charts
    3. Integration with Highcharts
    4. Integration with amCharts
    5. Integration with Google Charts
    6. Integration with FusionCharts
    7. Integration with any charting library
  8. Customizing
    1. Available tutorials
    2. Customizing the Toolbar
    3. Customizing appearance
    4. Customizing the context menu
    5. Customizing the grid
    6. Customizing the pivot charts
    7. Localizing the component
  9. Security
    1. Security in Flexmonster
    2. Security aspects of connecting to an OLAP cube
      1. Ways of connecting to an OLAP cube
      2. The data transfer process
      3. Data security
      4. Data access management
  10. Updating to the latest version
    1. Updating to the latest version
    2. Release notes
    3. Migration guide from 2.8 to 2.9
    4. Migration guide from 2.7 to 2.8
    5. Migration guide from 2.6 to 2.7
    6. Migration guide from 2.5 to 2.6
    7. Migration guide from 2.4 to 2.5
    8. Migration guide from 2.3 to 2.4
    9. Migration guide from 2.2 to 2.3
  11. Flexmonster CLI Reference
    1. Overview
    2. Troubleshooting the CLI
    3. flexmonster create
    4. flexmonster add
    5. flexmonster update
    6. flexmonster version
    7. flexmonster help
  12. Documentation for older versions
Table of contents

Date and time formatting

This tutorial explains how to format date and time fields when using JSON, CSV, Flexmonster Data Server, MongoDB, and the custom data source API. If using another data source type, format date and time fields as follows:

  • For Microsoft Analysis Services, Flexmonster uses date formatting configured inside the cube.
  • For Elasticsearch, you can configure date and time formatting using the mapping.format property.

See the sections below to format date and time fields in Flexmonster:

Basic date and time formatting

Step 1. Specify your date and time fields in the supported format

Flexmonster supports different input formats for date and time fields:

Input date format

Input date format depends on your data source:

JSON and CSV

For JSON and CSV data sources, the component supports the following date formats:

  1. ISO 8601. For example:
    • "2021-04-25" – Date.
    • "2021-04-25T21:30:05" – Date and time.
    • "2021-04-25T21:30:05+03:00" – Date and time with a time zone.
  2. Unix timestamp. For example, "2021-04-25" will be 1619298000 in the Unix timestamp format.
    Note that it is important to assign the date type to the Unix timestamp field explicitly. Otherwise, the component will treat this field as a numeric one. For details on setting the field’s type, see the next step.

Other formats aren’t officially supported and may have unexpected results.

Flexmonster Data Server

Flexmonster Data Server supports ISO 8601 as an input date format: 

  • "2021-04-25" – Date.
  • "2021-04-25T21:30:05" – Date and time.
  • "2021-04-25T21:30:05+03:00" – Date and time with a time zone.

Other formats aren’t officially supported and may have unexpected results.

MongoDB

When the MongoDB Connector is used, dates should be defined in the format supported by the MongoDB database. For example, you can define dates in the ISO 8601 format:

{
"Date": "2021-04-25"
}

Custom data source API

If using your implementation of the custom data source API, dates in the initial dataset can have any format. Your custom data source API server should process and pass them to Flexmonster as Unix timestamps. For example, "2021-04-25" will be 1619298000 in the Unix timestamp format.

In Microsoft Analysis Services or Elasticsearch, dates should be specified in a format supported by these data sources:

Input time format

In "json", "csv", and "api" data source types, it is possible to define time fields. They can be used to store a time interval (e.g., duration or elapsed time), which is not related to a specific date. Specify them as a number of seconds.

Here is how a time field can be specified in a JSON data source:

[
{
"Event": "Concert",
"Duration": 451515
}
]

Note that it is important to define the field’s type as "time" explicitly. Otherwise, the component will treat this field as a numeric one.

For details on setting the field’s type, see the next step.

Step 2. Choose a type for your date and time fields

By default, date fields in Flexmonster have the following types:

  • "date" – When using "json" and "csv" data source types. Fields of this type are split into three different fields: Year, Month, and Day.
  • "date string" – When using the "api" data source type. The component treats fields of this type as strings; they can be used in rows, columns, or report filters.

Time fields have the "number" type and are treated as numbers by default.

Based on your requirements, you can override these default types:

Set a type for all date fields in the dataset (only for JSON and CSV)

To set a type for all date fields, use the defaultDateType property of the Options Object. It allows overriding the default date type for "json" and "csv" data source types:

report: {
    options: {
        defaultDateType: "date string"
   }

}

Now the "date string" type will be applied to all date fields in the dataset.

Try a live sample on JSFiddle.

Set a type for a specific date field

Setting a type for a specific date field is possible with the Mapping Object. It provides the following types for date fields:

  • "date" – Fields of this type are split into three different fields: Year, Month, and Day. Only for "csv" and "json" data source types.
    For information on the input date format, see Step 1.1. Input date format.
  • "year/month/day" – Fields of this type are displayed as a multilevel hierarchy with the following levels: Year > Month > Day. Only for "csv" and "json" data source types.
    For information on the input date format, see Step 1.1. Input date format.
  • "year/quarter/month/day" – Fields of this type are displayed as a multilevel hierarchy with the following levels: Year > Quarter > Month > Day. Only for "csv" and "json" data source types.
    For information on the input date format, see Step 1.1. Input date format.
  • "date string" – Fields of this type are represented as strings and can be used in rows, columns, or report filters. Members of the "date string" fields are sorted as dates.
    Note that by default, "date string" fields are rounded down with the "1d" interval  (i.e., "04/25/2021T21:30:05" is rounded down to "04/25/2021T00:00:00"). If needed, you can set a custom interval for a field. Learn more about intervals: Rounding dates using the mapping.interval.
    To format "date string" fields, see the instructions below.
    For information on the input date format, see Step 1.1. Input date format.
  • "datetime" – You can select fields of this type for values. To format "datetime" fields, see the instructions below.
    For information on the input date format, see Step 1.1. Input date format.

Here is an example of setting the type for a date field using the Mapping Object:

report: {
dataSource: {
    data: [
        {
            "Date1": "2021-03-04T22:52:00",
            "Date2": "2021-03-04T22:52:00",
            "Date3": "2021-03-04T22:52:00"
        }
    ],
     mapping: {
        "Date1": {
            "type": "date"
        },
        "Date2": {
            "type": "date string"
        },
        "Date3": {
            "type": "datetime"
        }
    }

}
}

See a live sample on JSFiddle.

Set a type for a specific time field

By default, Flexmonster treats time fields as numbers, so it is needed to set their type explicitly. It can be done by setting the type property of the Mapping Object to "time".

The "time" type is used for the fields that store a time interval (e.g., duration or elapsed time), which is not related to a specific date. For information on the input time format, see the Input time format section.

Here is an example of how to define the "time" type in the mapping:

report: {
    dataSource: {
        data: [{
            "Event": "Concert",
            "Duration": 451515
        }],
        mapping: {
            "Duration": {
                "type": "time"
            }
        }

    },
    options: {
        timePattern: "d'd' HH'h' mm'min'"
    }
}

Now the Duration field will be displayed as 5d 05h 25min.

See the full example on JSFiddle.

To format "time" fields,  see this section.

Step 3. Format date and time fields

In Flexmonster, date fields are formatted using pattern strings. 

A pattern consists of letters that are replaced with date and time values in the formatted string. For example, in the pattern "yyyy/MM", the "yyyy" substring is replaced with a four-digit year followed by a "/" character, and the "MM" substring is replaced with a two-digit month.

You can define pattern strings for:

Format fields of the “date string” type

To format fields of the "date string" type, use the datePattern property of the Options Object. Its default pattern string is "dd/MM/yyyy".

Here is how the datePattern can be specified in the report:

report: {
options: {
datePattern: "yyyy.MM.dd"
},

dataSource: {
data: [
...
],
mapping: {
"Date": { "type": "date string" }
    }
}
}

Test or modify this example on JSFiddle.

Supported patterns for the "date string" fields are the following:

  • d – Day of the month. It is represented as a one- or two-digit number. For example, 2 or 18.
  • dd – Day of the month. It is represented as a two-digit number. For example, 02 or 18.
  • ddd – Day of the week. It is represented as a three-letter abbreviation of the day of the week. For example, Wed.
  • dddd – Day of the week. It is represented as the full name of the day of the week. For example, Wednesday.
  • M – Month. It is represented as a one- or two-digit number. For example, 3 or 11.
  • MM – Month. It is represented as a two-digit number. For example, 03.
  • MMM – Month. It is represented as a three-letter abbreviation of the name of the month. For example, Mar.
  • MMMM – Month. It is represented as the full name of the month. For example, March.
  • yy – Year. It is represented as a two-digit number. For example, 16.
  • yyyy – Year. It is represented as a four-digit number. For example, 2016.
  • UTC: – indicates that the UTC time zone should be used. Example format: "UTC:dd/MM/yyyy".
  • GMT+-N: – indicates the time zone to use, where N can be changed from 1 to 12. Example format: "GMT+6:dd/MM/yyyy".

Have a look at how the datePattern can be specified:

Pattern Example of a formatted date
"yyyy-MM-dd" 2021-05-25
"M/d/yy" 4/25/21
"MMM d, yyyy" Mar 25, 2021
"MMMM d, yyyy" March 25, 2021
"dddd, MMMM d, yyyy" Sunday, March 25, 2021

Format fields of the “datetime” type

To format fields of the "datetime" type, use the dateTimePattern property of the Options Object. Its default pattern string is "dd/MM/yyyy HH:mm:ss".

Here is how the dateTimePattern can be specified in the report:

report: {
options: {
dateTimePattern: "yyyy.MM.dd HH:mm TT"
},

dataSource: {
data: [
...
],
mapping: {
"Date": { "type": "datetime" }
    }
}
}

See the full code on JSFiddle.

Supported patterns for the "datetime" fields are the following:

  • d – Day of the month. It is represented as a one or two-digit number. For example, 2 or 18.
  • dd – Day of the month. It is represented as a two-digit number. For example, 02 or 18.
  • ddd – Day of the week. It is represented as a three-letter abbreviation of the day of the week. For example, Wed.
  • dddd – Day of the week. It is represented as the full name of the day of the week. For example, Wednesday.
  • M – Month. It is represented as a one or two-digit number. For example, 3 or 11.
  • MM – Month. It is represented as a two-digit number. For example, 03.
  • MMM – Month. It is represented as a three-letter abbreviation of the name of the month. For example, Mar.
  • MMMM – Month. It is represented as the full name of the month. For example, March.
  • yy – Year. It is represented as a two-digit number. For example, 16.
  • yyyy – Year. It is represented as a four-digit number. For example, 2016.
  • h – Hour of the day using the 12-hour format [1 – 12]. It is represented as a one or two-digit number. For example, 1 or 12.
  • hh – Hour of the day using the 12-hour format [1 – 12]. It is represented as a two-digit number. For example, 01 or 12.
  • H – Hour of the day using the 24-hour format [0 – 23]. It is represented as a one or two-digit number. For example, 0 or 23.
  • HH – Hour of the day using the 24-hour format [0 – 23]. It is represented as a two-digit number. For example, 00 or 23.
  • k – Hour of the day using the 24-hour format [1 – 24]. It is represented as a one or two-digit number. For example, 1 or 24.
  • kk – Hour of the day using the 24-hour format [1 – 24]. It is represented as a two-digit number. For example, 01 or 24.
  • m – Minutes [0 – 59]. It is represented as a one or two-digit number. For example, 0 or 59.
  • mm – Minutes [0 – 59]. It is represented as a two-digit number. For example, 00 or 59.
  • s – Seconds [0 – 59]. It is represented as a one or two-digit number. For example, 0 or 59.
  • ss – Seconds [0 – 59]. It is represented as a two-digit number. For example, 00 or 59.
  • l – Milliseconds. It is represented as a three-digit number. For example, 100.
  • L – 10 Milliseconds. It is represented as a two-digit number (rounded, if needed). For example, 10.
  • t – am/pm – a one-letter indicator. For example, a or p.
  • tt – am/pm – a two-letter indicator. For example, am or pm.
  • T – AM/PM – a one-letter indicator. For example, A or P.
  • TT – AM/PM – a two-letter indicator. For example, AM or PM.
  • UTC: – indicates that the UTC time zone should be used. Example format: "UTC:dd/MM/yyyy HH:mm:ss".
  • GMT+-N: – indicates the time zone to use, where N can be changed from 1 to 12. Example format: "GMT+6:dd/MM/yyyy HH:mm:ss".

Have a look at how the dateTimePattern can be specified:

Pattern Example of a formatted date
"yyyy-MM-dd" 2021-05-25
"M/d/yy, h:mm TT" 4/25/21, 9:30 PM
"MMM d, yyyy, h:mm:ss TT" Mar 25, 2021, 9:30:00 PM
"MMMM d, yyyy" March 25, 2021
"dddd, MMMM d, yyyy" Sunday, March 25, 2021
"h:mm TT" 9:30 PM
"h:mm:ss TT" 9:30:05 PM

Format fields of the “time” type

To format fields of the "time" type, use the timePattern property of the Options Object. Its default pattern string is "HH:mm:ss".

Here is how the timePattern can be specified in the report:

report: {
options: {
timePattern: "d'd' HH'h' mm'min'"
},

dataSource: {
data: [
...
],
mapping: {
"Time": { "type": "time" }
}
}
}

Check out a full example on JSFiddle.

Supported patterns for the "time" fields are the following:

  • d – Days. It is represented as a one- or two-digit number. For example, 5 or 11.
  • dd – Days. It is represented as a two-digit number. For example, 05 or 11.
  • H – Hours. It is represented as a one- or two-digit number. For example, 6 or 15.
  • HH – Hours. It is represented as a two-digit number. For example, 06 or 15.
  • HHH – Hours. Displays time data in hours even when the number of hours is greater than 24. For example, 46 or 15.
  • m – Minutes. It is represented as a one- or two-digit number. For example, 2 or 10.
  • mm – Minutes. It is represented as a two-digit number. For example, 02 or 10.
  • s – Seconds. It is represented as a one- or two-digit number. For example, 3 or 16.
  • ss – Seconds. It is represented as a two-digit number. For example, 03 or 16.

Have a look at how the timePattern can be specified:

Pattern Example of a formatted time
"HH:mm:ss" 21:30:00
"h:mm TT" 9:30 PM
"h:mm:ss TT" 9:30:05 PM

Format specific fields (overrides other patterns)

Formatting specified in the Options Object applies to all the fields of the respective type (e.g., all "date string" fields are formatted according to the datePattern). To format a specific field, use the format property of the Mapping Object.

It works the same way as datePattern, dateTimePattern, and timePattern options and overrides their values. Here is an example of how to define formatting for a certain field:

report: {
dataSource: {
data: [
...
],
mapping: {
"OrderDate": {
        type: "date string",
         format: "MM/dd/yyyy"
    }
}
}
}

Try a live sample on JSFiddle.

In the example above, datePattern is not applied to the OrderDate field since it has the format property in the mapping.

Managing time zones

By default, Flexmonster uses the user’s local time zone in dates.

For example, your dataset contains a date with the GMT+2 time zone: "2021-04-25T21:30:05+02:00". Flexmonster will display this date according to your local time zone. Try a live demo on JSFiddle.

If needed, you can set another time zone for your date fields.

Setting a time zone in the component affects only date representation; the original data is not changed.

You can set time zones:

Set a time zone for all date fields

To set a timezone for all date fields, use the dateTimezoneOffset property. It is a number that represents the difference in hours between the needed time zone and UTC.

For example, the GMT-5 time zone can be set like this:

report: {
options: {
       dateTimezoneOffset: -5
   },
   dataSource: {
       ...
   }
}

See an example on JSFiddle.

Set a time zone for fields of a certain date type

You can set a time zone for fields of a certain type as follows:

  • For fields of the "date string" type, set a time zone using the datePattern option.
    To set a time zone, include "GMT+-N:" at the beginning of the pattern (e.g., "GMT+6:dd/MM/yyyy"). N can be changed from 1 to 12. See an example on JSFiddle.
    Note that a time zone from the datePattern will override a time zone from the dateTimezoneOffset.
  • For fields of the "datetime" type, set a time zone using the dateTimePattern option.
    To set a time zone, include "GMT+-N:" at the beginning of the pattern (e.g., "GMT+6:dd/MM/yyyy HH:mm:ss"). N can be changed from 1 to 12. See an example on JSFiddle.
    Note that a time zone from the dateTimePattern will override a time zone from the dateTimezoneOffset.
  • For all other date types, use the approach described in step 4.1.

Set a time zone for specific fields (overrides other time zones)

You can set a time zone for a specific field using the format property of the Mapping Object. This option is available for fields of the "date string" and "datetime" types.

To set a time zone, include "GMT+-N:" at the beginning of the pattern (e.g., "GMT+6:dd/MM/yyyy HH:mm:ss"). N can be changed from 1 to 12. See an example on JSFiddle.

A time zone from the format property will override time zones from datePattern, dateTimePattern, and dateTimezoneOffset properties.

Rounding dates using the mapping.interval

If needed, dates in Flexmonster can be rounded down with the mapping.interval property. This feature can be used to group dates by a certain interval on the pivot table.

Fields of the "date string" type have the "1d" interval by default.

In the code snippet below, all dates have the same day part, but different time parts. The "1d" interval will round all dates to 2021-04-25T00:00:00:

report: {
    dataSource: {         
        data: [
            {
                "DeliveryDate": "2021-04-25T21:30:05",
                "Price": 200
            },
            {
                "DeliveryDate": "2021-04-25T23:55:00",
                "Price": 150
           }
        ], 
        mapping: {
            "Date": {
                interval: "1d",
                type: "datetime"
            }
        }
    }
}

See an example on JSFiddle.

What’s next?

You may be interested in the following articles: