Skip to main content

Date-time functions

Date Functions#

now#

The now() function returns the current time value in milliseconds.

Syntax:

new NameSpace( "date").now();

Returns: Number

Example:

now = new NameSpace("date").now();log now; // 1626971728677

getFormattedTime#

The getFormattedTime() takes time (in milliseconds format) and format as arguments and returns formatted date/time in the specified format.

Syntax:

new NameSpace("date").getFormattedTime(Number time, String format);

Parameters:

ParamData typeDescription
timeNumberTime in milliseconds to be formatted.
formatStringThe date format as per Java standard.

Returns: String

Example:

currentTime = new NameSpace("date").now();format = "MMM dd, yyyy hh:mm a";formattedTime = new NameSpace("date").getFormattedTime(currentTime, format);log formattedTime; // sample: Jul 26, 2021 08:06 PM

getCurrentHour#

The getCurrentHour() functions returns the current time hour

Syntax:

new NameSpace( "date").getCurrentHour();

Returns: Number

Example:

currentHour = new NameSpace("date").getCurrentHour();log currentHour;

getCurrentDate#

The getCurrentDate() functions returns the current date

Syntax:

new NameSpace( "date").getCurrentDate();

Returns: Number

Example:

currentDate = new NameSpace("date").getCurrentDate();log currentDate;

getCurrentDay#

The getCurrentDay() functions returns the current Day in number

Syntax:

new NameSpace( "date").getCurrentDay();

Returns: Number

Example:

currentDay = new NameSpace("date").getCurrentDay();log currentDay;

getCurrentMonth#

The getCurrentMonth() functions returns the current Month

Syntax:

new NameSpace( "date").getCurrentMonth();

Returns: Number

Example:

CurrentMonth = new NameSpace("date").getCurrentMonth();log CurrentMonth;

getCurrentYear#

The getCurrentYear() functions returns the current Year

Syntax:

new NameSpace( "date").getCurrentYear();

Returns: Number

Example:

CurrentYear = new NameSpace("date").getCurrentYear();log CurrentYear;

getCurrentMonthDays#

Get number of days in a current month or specified month.

Syntax:

new NameSpace( "date").getCurrentMonthDays();

Returns: Number

Example:

noOfDays = new NameSpace("date").getCurrentMonthDays();log noOfDays;
timeInMillis = 1612463400000;noOfDaysInParticularMonth = new NameSpace("date").getCurrentMonthDays(timeInMillis);log noOfDaysInParticularMonth;

addSeconds#

The addSecondsfunction takes a date-time or time value and count as arguments. It returns the date-time or time value after adding the specified number of seconds to it.

Syntax:

new NameSpace("date").addSeconds(time ,count);

Parameters:

ParamData typeDescription
timeNumberThe time value to which the specified number of seconds should be added.
countNumberThe number of seconds to be added to date-time or time value

Returns: Number

Example:

currentTime = 1627045195249;addSeconds = new NameSpace("date").addSeconds(currentTime , 50);log addSeconds;

addMinutes#

The addMinutes function takes a date-time or Count and numberOfMins as arguments. It returns the date-time or time value after adding the specified number of minutes to it.

Syntax:

new NameSpace("date").addMinutes(time ,count);

Parameters:

ParamData typeDescription
timeNumberThe time value to which the specified number of minutes should be added.
countNumberThe number of minutes to be added to date-time or time value

Returns: Number

Example:

currentTime = 1627045195249;addMinutes = new NameSpace("date").addMinutes(currentTime , 50);log addMinutes;

addHours#

The addHour function takes a date-time or time value and count as arguments. It returns the date-time or time value after adding the specified number of hours to it.

Syntax:

new NameSpace("date").addHours(time ,count);

Parameters:

ParamData typeDescription
timeNumberThe time value to which the specified number of hours should be added.
countNumberThe number of hours to be added to date-time or time value

Returns: Number

Example:

currentTime = 1627045195249;addHours = new NameSpace("date").addHours(currentTime , 4);log addHours;

addDays#

The addDay() function takes dateTimeValue and count as arguments. It returns the dateTimeValue after adding the specified number of days to it.

Syntax:

new NameSpace("date").addDays(time ,count);

Parameters:

ParamData typeDescription
timeNumberThe time value to which the specified number of days should be added.
countNumberThe number of days to be added to date-time or time value

Returns: Number

Example:

currentTime = 1627045195249;addDays = new NameSpace("date").addDays(currentTime , 10);log addDays;

addWeeks#

The addWeeks() function takes dateTimeValue and count as arguments. It returns the dateTimeValue after adding the specified number of Weeks to it.

Syntax:

new NameSpace("date").addWeeks(time ,count);

Parameters:

ParamData typeDescription
timeNumberThe time value to which the specified number of weeks hours should be added.
countNumberThe number of weeks to be added to date-time or time value

Returns: Number

Example:

currentTime = 1627045195249;addWeeks = new NameSpace("date").addWeeks(currentTime , 4);log addWeeks;

addMonths#

The addMonth() function takes dateTimeValue and count as arguments. It returns the dateTimeValue after adding the specified number of months to it.

Syntax:

new NameSpace("date").addMonths(time ,count);

Parameters:

ParamData typeDescription
timeNumberThe time value to which the specified number of months should be added.
countNumberThe number of months to be added to date-time or time value

Returns: Number

Example:

currentTime = 1627045195249;addMonths = new NameSpace("date").addMonths(currentTime , 3);log addMonths;

addYears#

The addMonth() function takes dateTimeValue and count as arguments. It returns the dateTimeValue after adding the specified number of years to it.

Syntax:

new NameSpace("date").addYears(time ,count);

Parameters:

ParamData typeDescription
timeNumberThe time value to which the specified number of years should be added.
countNumberThe number of years to be added to date-time or time value

Returns: Number

Example:

currentTime = 1627045195249;addYears = new NameSpace("date").addYears(currentTime , 3);log addYears;

getDayStartTime#

The getDayStartTime() function returns the current day started time in milliseconds

Syntax:

new NameSpace("date").getDayStartTime(time);

Parameters:

ParamData typeDescription
timeNumber(Optional) To get specific day start time

Returns: Number

Example:

dayStartedTime = new NameSpace("date").getDayStartTime();log dayStartedTime;

getMonthStartTime#

The getMonthStartTime() functions returns the current month started time in milliseconds

Syntax:

new NameSpace("date").getMonthStartTime(time);

Parameters:

ParamData typeDescription
timeNumber(Optional) To get specific month start time

Returns: Number

Example:

monthStartedTime = new NameSpace("date").getMonthStartTime();log monthStartedTime;

getMonthEndTime#

The getMonthEndTime() functions returns the current month end time in milliseconds

Syntax:

new NameSpace("date").getMonthEndTime(time);

Parameters:

ParamData typeDescription
timeNumber(Optional) To get specific month end time

Returns: Number

Example:

monthEndTime = new NameSpace("date").getMonthEndTime();log monthEndTime;

getPreviousMonthStartDate#

The getPreviousMonthStartDate() functions returns the previous month started date in milliseconds

Syntax:

new NameSpace("date").getPreviousMonthStartDate();

Returns: Number

Example:

previousMonthStartedTime = new NameSpace("date").getPreviousMonthStartDate();log previousMonthStartedTime;

getPreviousMonthEndDate#

The getPreviousMonthStartDate() functions returns the previous month end date in milliseconds

Syntax:

new NameSpace("date").getPreviousMonthEndDate();

Returns: Number

Example:

previousMonthEndTime = new NameSpace("date").getPreviousMonthEndDate();log previousMonthEndTime;

getPreviousQuarterStartDate#

  • Quarterly is every 3 months. Explanation: A quarter is a fourth part, I.e. 1/4 th. A year consists of 12 months.

The getPreviousQuarterStartDate() functions returns the previous quater month start date in milliseconds

Syntax:

new NameSpace("date").getPreviousQuarterStartDate();

Returns: Number

Example:

previousQuarterStartDate = new NameSpace("date").getPreviousQuarterStartDate();log previousQuarterStartDate;

getPreviousQuarterEndDate#

The getPreviousQuarterEndDate() functions returns the previous quater month end date in milliseconds

Syntax:

new NameSpace("date").getPreviousQuarterEndDate();

Returns: Number

Example:

previousQuarterEndDate = new NameSpace("date").getPreviousQuarterEndDate();log previousQuarterEndDate;

getLastMonthDays#

The getLastMonthDays() functions returns last month days count

Syntax:

new NameSpace( "date").getLastMonthDays(Time);

Returns: Number

Example:

monthStartedTime = new NameSpace("date").getLastMonthDays();log monthStartedTime;

getDaysBetween#

The daysBetween function takes startTime and endTime as arguments and returns the number of days between them.

Syntax:

new NameSpace( "date").getDaysBetween(startTime , endTime);

Parameters:

ParamData typeDescription
startTimeNumberThe starting date.
endTimeNumberThe ending date.

Returns: Number

Example:

startTime = 1626805800000;endTime = 1627237800000;daysBetween = new NameSpace("date").getDaysBetween(startTime , endTime);log daysBetween;

getDateRange#

The getDateRange() functions data operator as a argument return start time and end time in milliseconds

The below operators are supported in getDateRange function

  • Today
  • Tomorrow
  • Yesterday
  • Current Week
  • Last Week
  • Current Month
  • Last Month
  • Last Quarter
  • Current Year
  • Last Year

Syntax

new NameSpace( "date").getDateRange(operator);

Parameters:

ParamData typeDescription
Date OperatorsNumberThe number of hours to be converted to day.

Returns: dateRange

Example:

time = new NameSpace("date").getDateRange("Last Year");log time; // 1577858400000, 1609480799999

minToHour#

Convert minute to hours.

Syntax:

new NameSpace( "date").minsToHour(minutes);

Parameters:

ParamData typeDescription
minutesNumberThe number of minutes to be converted to hours.

Returns: Number

Example:

minutes = 120;hours = new NameSpace("date").minsToHour(minutes);log hours; // 2

secToHour#

The secToHour function covert seconds to hours

Syntax:

new NameSpace( "date").secToHour(seconds);

Parameters:

ParamData typeDescription
secondsNumberThe number of seconds to be converted to hours.

Returns: Number

Example:

seconds = 3600;hours = new NameSpace("date").secToHour(seconds);log hours; // 1

hourToDay#

The hourToDay() function convert hours to day

Syntax:

new NameSpace( "date").hourToDay(hours);

Parameters:

ParamData typeDescription
hourNumberThe number of hours to be converted to day.

Returns: Number

Example:

hours = 48;day = new NameSpace("date").hourToDay(hours);log day; // 2

getRFC3339FormatedDateString#

The getRFC3339FormatedDateString() takes time (in milliseconds format) and format as RFC3339 Format and returns formatted date/time.

Syntax:

new NameSpace("date").getRFC3339FormatedDateString(Number time);

Parameters:

ParamData typeDescription
timeNumberTime in milliseconds to be formatted.

Returns: String

Example:

currentTime = new NameSpace("date").now();formattedTime = new NameSpace("date").getRFC3339FormatedDateString(currentTime);log formattedTime; //2022-02-07T06:20:23Z

getMilliSecondFromRFC3339FormatedDateString#

The getMilliSecondFromRFC3339FormatedDateString() takes RFC3339 Format time string as input and returns milliseconds.

Syntax:

new NameSpace("date").getMilliSecondFromRFC3339FormatedDateString(String time);

Parameters:

ParamData typeDescription
timeNumberTime in RFC3339 to be formatted in milliseconds.

Returns: Number

Example:

currentTime = new NameSpace("date").now();formattedTime = new NameSpace("date").getRFC3339FormatedDateString(currentTime);log formattedTime; //2022-02-07T06:20:23ZmillisecTime= new NameSpace("date").getMilliSecondFromRFC3339FormatedDateString(formattedTime);log millisecTime; //1644228859000

getMilliSecondFromFormatedDateString#

The getMilliSecondFromFormatedDateString() takes Formatted time string as input and returns milliseconds.

Syntax:

new NameSpace("date").getMilliSecondFromFormatedDateString(String time, String format);

Parameters:

ParamData typeDescription
timeNumberTime in RFC3339 to be formatted in milliseconds.

Returns: Number

Example:

millisecTime= new NameSpace("date").getMilliSecondFromFormatedDateString("20-01-2001 11:04:02", "dd-MM-yyyy HH:mm:ss");log millisecTime; //979968842000

getPreviousMonthName#

The getPreviousMonthName() functions returns the previous month name along with year.

Syntax:

new NameSpace("date").getPreviousMonthName();

Returns: String

Example:

previousMonthName = new NameSpace("date").getPreviousMonthName();log previousMonthName; // January 2022

getPreviousLastMonthName#

The getPreviousLastMonthName() functions returns the last month's before month name along with year.

Syntax:

new NameSpace("date").getPreviousLastMonthName();

Returns: String

Example:

PreviousLastMonthName = new NameSpace("date").getPreviousLastMonthName();log PreviousLastMonthName; // December 2021

getMonthRange#

The getMonthRange() functions returns the start and end date of the given month. If argument is passed it returns the month of the given date or else it returns the current month start and end date.

Syntax:

new NameSpace("date").getMonthRange();

Returns: Number

Example:

now = new NameSpace("date").now();monthRange = new NameSpace("date").getMonthRange(now);log monthRange; //1643653800000, 1646072999999
previousMonthStartedTime = new NameSpace("date").getPreviousMonthStartDate();monthRange = new NameSpace("date").getMonthRange(previousMonthStartedTime);log monthRange; //1640975400000, 1643653799999

getDayEndTime#

The getDayEndTime() functions returns the day end time of the given day. If argument is passed it returns the end time of the given date or else it returns the current day end time.

Syntax:

new NameSpace("date").getDayEndTime();

Returns: Number

Example:

dayEndTime = new NameSpace("date").getDayEndTime();log dayEndTime; //1644258599999

getPreviousQuarterStartDate#

The getPreviousQuarterStartDate() functions returns the start date in millis format of the previous quater month. A year can be split into four quaters, that is 3 months in each quater.

Syntax:

new NameSpace("date").getPreviousQuarterStartDate();

Returns: Number

Example:

previousQuarterStartDate = new NameSpace("date").getPreviousQuarterStartDate();log previousQuarterStartDate; //1635705000000

getPreviousQuarterEndDate#

The getPreviousQuarterEndDate() functions returns the end date in millis format of the previous quater month. A year can be split into four quaters, that is 3 months in each quater.

Syntax:

new NameSpace("date").getPreviousQuarterEndDate();

Returns: Number

Example:

previousQuarterEndDate = new NameSpace("date").getPreviousQuarterEndDate();log previousQuarterEndDate; //1643653799999

dateRange#

The dateRange() function gets startdate and enddate as argument in millisformat, and returns the object containing startdate and enddate.

Syntax:

new NameSpace("date").dateRange(Number StartDate,Number EndDate);

Returns: Object

Example:

obj_dateRange = new NameSpace("date").dateRange(1640975400000, 1643653799999);log obj_dateRange; //1640975400000, 1643653799999

getDateOperator#

The getDateOperator() function take data operator(for operator refer getDateRange function) as a argument returns its respective Id as number.

Syntax:

new NameSpace("date").getDateOperator(String OperatorName);

Returns: Number

Example:

dateOperator = new NameSpace("date").getDateOperator("Tomorrow");log dateOperator; //23

DateRange Functions#

getStartTime#

The object which has been got from dateRange function is passed as argument to this function, one can get startDate and endDate by using the syntax objectname.getStartTime or getEndTime.

Syntax:

Object DateRange.getStartTime();

Returns: Number

Example:

obj_dateRange = new NameSpace("date").dateRange(1640975400000, 1643653799999);log obj_dateRange; //1640975400000, 1643653799999log obj_dateRange.getStartTime(); // 1640975400000

getEndTime#

The object which has been got from dateRange function is passed as argument to this function, one can get startDate and endDate by using the syntax objectname.getStartTime or getEndTime.

Syntax:

Object DateRange.getEndTime();

Returns: Number

Example:

obj_dateRange = new NameSpace("date").dateRange(1640975400000, 1643653799999);log obj_dateRange; //1640975400000, 1643653799999log obj_dateRange.getEndTime(); // 1643653799999

create#

The create() functions gets startTime, endTime, baseline operators as arguments and returns start time and end time in milliseconds

The below operators are supported in create function

  • Previous Period
  • Previous Hour
  • Previous Day
  • Previous Week
  • Previous Month
  • Previous Quarter
  • Previous Year
  • Previous Period

Syntax:

new NameSpace("dateRange").create(Number startTime,Number endTime,String baseLineOperators );

Returns: Number

Example:

obj= new NameSpace("dateRange").create(1640975400000,1643653799999,"Previous Month");  log obj; //1637951400000, 1640629799999

getMilliSeconds#

The getMilliSeconds() takes formatted time string as inputs and returns milliseconds.

Syntax:

new NameSpace("date").getMilliSeconds(String time, String format);

Parameters:

ParamData typeDescription
timeNumberTime in RFC3339 to be formatted in milliseconds.
formatStringThe date format as per Java standard.

Returns: Number

Example:

timec= "20-01-2001 11:04:02";format = "dd-MM-yyyy HH:mm:ss";millisecTime = new NameSpace("date").getMilliSeconds(time,format);log millisecTime;