Date-time functions
- Date Functions
- now
- getFormattedTime
- getCurrentHour
- getCurrentDate
- getCurrentDay
- getCurrentMonth
- getCurrentYear
- getCurrentMonthDays
- addSeconds
- addMinutes
- addHours
- addDays
- addWeeks
- addMonths
- addYears
- getDayStartTime
- getMonthStartTime
- getMonthEndTime
- getPreviousMonthStartDate
- getPreviousMonthEndDate
- getPreviousQuarterStartDate
- getPreviousQuarterEndDate
- getLastMonthDays
- getDaysBetween
- getDateRange
- minToHour
- secToHour
- hourToDay
- getRFC3339FormatedDateString
- getMilliSecondFromRFC3339FormatedDateString
- getMilliSecondFromFormatedDateString
- getPreviousMonthName
- getPreviousLastMonthName
- getMonthRange
- getDayEndTime
- getPreviousQuarterStartDate
- getPreviousQuarterEndDate
- dateRange
- getDateOperator
- DateRange Functions
#
Date Functions#
nowThe 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
#
getFormattedTimeThe 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:
Param | Data type | Description |
---|---|---|
time | Number | Time in milliseconds to be formatted. |
format | String | The 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
#
getCurrentHourThe getCurrentHour() functions returns the current time hour
Syntax:
new NameSpace( "date").getCurrentHour();
Returns: Number
Example:
currentHour = new NameSpace("date").getCurrentHour();log currentHour;
#
getCurrentDateThe getCurrentDate() functions returns the current date
Syntax:
new NameSpace( "date").getCurrentDate();
Returns: Number
Example:
currentDate = new NameSpace("date").getCurrentDate();log currentDate;
#
getCurrentDayThe getCurrentDay() functions returns the current Day in number
Syntax:
new NameSpace( "date").getCurrentDay();
Returns: Number
Example:
currentDay = new NameSpace("date").getCurrentDay();log currentDay;
#
getCurrentMonthThe getCurrentMonth() functions returns the current Month
Syntax:
new NameSpace( "date").getCurrentMonth();
Returns: Number
Example:
CurrentMonth = new NameSpace("date").getCurrentMonth();log CurrentMonth;
#
getCurrentYearThe getCurrentYear() functions returns the current Year
Syntax:
new NameSpace( "date").getCurrentYear();
Returns: Number
Example:
CurrentYear = new NameSpace("date").getCurrentYear();log CurrentYear;
#
getCurrentMonthDaysGet 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;
#
addSecondsThe 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:
Param | Data type | Description |
---|---|---|
time | Number | The time value to which the specified number of seconds should be added. |
count | Number | The 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;
#
addMinutesThe 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:
Param | Data type | Description |
---|---|---|
time | Number | The time value to which the specified number of minutes should be added. |
count | Number | The 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;
#
addHoursThe 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:
Param | Data type | Description |
---|---|---|
time | Number | The time value to which the specified number of hours should be added. |
count | Number | The 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;
#
addDaysThe 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:
Param | Data type | Description |
---|---|---|
time | Number | The time value to which the specified number of days should be added. |
count | Number | The 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;
#
addWeeksThe 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:
Param | Data type | Description |
---|---|---|
time | Number | The time value to which the specified number of weeks hours should be added. |
count | Number | The 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;
#
addMonthsThe 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:
Param | Data type | Description |
---|---|---|
time | Number | The time value to which the specified number of months should be added. |
count | Number | The 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;
#
addYearsThe 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:
Param | Data type | Description |
---|---|---|
time | Number | The time value to which the specified number of years should be added. |
count | Number | The 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;
#
getDayStartTimeThe getDayStartTime() function returns the current day started time in milliseconds
Syntax:
new NameSpace("date").getDayStartTime(
time
);
Parameters:
Param | Data type | Description |
---|---|---|
time | Number | (Optional) To get specific day start time |
Returns: Number
Example:
dayStartedTime = new NameSpace("date").getDayStartTime();log dayStartedTime;
#
getMonthStartTimeThe getMonthStartTime() functions returns the current month started time in milliseconds
Syntax:
new NameSpace("date").getMonthStartTime(
time
);
Parameters:
Param | Data type | Description |
---|---|---|
time | Number | (Optional) To get specific month start time |
Returns: Number
Example:
monthStartedTime = new NameSpace("date").getMonthStartTime();log monthStartedTime;
#
getMonthEndTimeThe getMonthEndTime() functions returns the current month end time in milliseconds
Syntax:
new NameSpace("date").getMonthEndTime(
time
);
Parameters:
Param | Data type | Description |
---|---|---|
time | Number | (Optional) To get specific month end time |
Returns: Number
Example:
monthEndTime = new NameSpace("date").getMonthEndTime();log monthEndTime;
#
getPreviousMonthStartDateThe 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;
#
getPreviousMonthEndDateThe 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;
#
getPreviousQuarterEndDateThe 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;
#
getLastMonthDaysThe getLastMonthDays() functions returns last month days count
Syntax:
new NameSpace( "date").getLastMonthDays(
Time
);
Returns: Number
Example:
monthStartedTime = new NameSpace("date").getLastMonthDays();log monthStartedTime;
#
getDaysBetweenThe daysBetween function takes startTime and endTime as arguments and returns the number of days between them.
Syntax:
new NameSpace( "date").getDaysBetween(
startTime
,endTime
);
Parameters:
Param | Data type | Description |
---|---|---|
startTime | Number | The starting date. |
endTime | Number | The ending date. |
Returns: Number
Example:
startTime = 1626805800000;endTime = 1627237800000;daysBetween = new NameSpace("date").getDaysBetween(startTime , endTime);log daysBetween;
#
getDateRangeThe 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:
Param | Data type | Description |
---|---|---|
Date Operators | Number | The number of hours to be converted to day. |
Returns: dateRange
Example:
time = new NameSpace("date").getDateRange("Last Year");log time; // 1577858400000, 1609480799999
#
minToHourConvert minute to hours.
Syntax:
new NameSpace( "date").minsToHour(
minutes
);
Parameters:
Param | Data type | Description |
---|---|---|
minutes | Number | The number of minutes to be converted to hours. |
Returns: Number
Example:
minutes = 120;hours = new NameSpace("date").minsToHour(minutes);log hours; // 2
#
secToHourThe secToHour function covert seconds to hours
Syntax:
new NameSpace( "date").secToHour(
seconds
);
Parameters:
Param | Data type | Description |
---|---|---|
seconds | Number | The number of seconds to be converted to hours. |
Returns: Number
Example:
seconds = 3600;hours = new NameSpace("date").secToHour(seconds);log hours; // 1
#
hourToDayThe hourToDay() function convert hours to day
Syntax:
new NameSpace( "date").hourToDay(
hours
);
Parameters:
Param | Data type | Description |
---|---|---|
hour | Number | The number of hours to be converted to day. |
Returns: Number
Example:
hours = 48;day = new NameSpace("date").hourToDay(hours);log day; // 2
#
getRFC3339FormatedDateStringThe getRFC3339FormatedDateString() takes time (in milliseconds format) and format as RFC3339 Format and returns formatted date/time.
Syntax:
new NameSpace("date").getRFC3339FormatedDateString(
Number
time);
Parameters:
Param | Data type | Description |
---|---|---|
time | Number | Time 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
#
getMilliSecondFromRFC3339FormatedDateStringThe getMilliSecondFromRFC3339FormatedDateString() takes RFC3339 Format time string as input and returns milliseconds.
Syntax:
new NameSpace("date").getMilliSecondFromRFC3339FormatedDateString(
String
time);
Parameters:
Param | Data type | Description |
---|---|---|
time | Number | Time 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
#
getMilliSecondFromFormatedDateStringThe getMilliSecondFromFormatedDateString() takes Formatted time string as input and returns milliseconds.
Syntax:
new NameSpace("date").getMilliSecondFromFormatedDateString(
String
time,String
format);
Parameters:
Param | Data type | Description |
---|---|---|
time | Number | Time 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
#
getPreviousMonthNameThe 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
#
getPreviousLastMonthNameThe 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
#
getMonthRangeThe 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
#
getDayEndTimeThe 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
#
getPreviousQuarterStartDateThe 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
#
getPreviousQuarterEndDateThe 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
#
dateRangeThe 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
#
getDateOperatorThe 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#
getStartTimeThe 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
#
getEndTimeThe 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
#
createThe 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
#
getMilliSecondsThe getMilliSeconds() takes formatted time string as inputs and returns milliseconds.
Syntax:
new NameSpace("date").getMilliSeconds(
String
time,String
format);
Parameters:
Param | Data type | Description |
---|---|---|
time | Number | Time in RFC3339 to be formatted in milliseconds. |
format | String | The 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;