You are here: Using BML > Functions & Scripts > Date Functions

Date Functions

OVERVIEW

Date functions are often used when evaluating and calculating quotes in Commerce. As an example, they are used to set quote expiration dates. Dates are always strings in Commerce, but can be converted to dates using the functions included in this article.

ADMINISTRATION

Closedadddays()

This function returns the date which is obtained after adding X number of days to a particular date. Example Use Case: Often used in Commerce to set the time a quote is valid, or when it expires.

Syntax: adddays(date, num_of_days)

Parameters:

Return Type: Date

Example of adddays():

We will use multiple functions to accomplish the following:


Closedcomparedates()

Use this function to compare two dates based on date and time.

Syntax: comparedates(Date date1, Date date2)

Parameters:

# Parameter Data Type Description
1 date1 Date Represents the given date.
2 date2 Date Represents another given date.

Return Type: Integer

Example of comparedates():

If... ...Returns
Both dates are equal 0
First date is before second date -1
First date is after second date 1

This function also considers the time for a given date. For "11/04/2009 00:02:00" and "11/04/2009 00:01:00", the function returns 1.


Closeddatetostr()

This function converts a date to a string. It can take an optional parameter that can return a formatted string. Example Use Case: Date fields in commerce are considered string fields, so to return a date to a commerce attribute you need to convert it to a string first.

Syntax: datetostr(date, [dateFormat]

Parameters:

Return Type: Boolean

Example of datetostr():


Closedgetcurrenttimeinmillis()

This function returns the current time in milliseconds.

Syntax: Integer getcurrenttimeinmillis()

Return Type: Boolean


Closedgetdate()

This function returns the current date/time based on the base time zone you have set-up in your application. The function takes a parameter and returns a date, with or without time. Example Use Case: Find the current date.

Syntax: getdate([boolean includeTime])

Parameters:

Return Type: Date

Example of getdate():

Example of getdate(false):


Closedgetdiffindays()

This function calculates the number of days between two different dates. Example Use Case: Check to see if a quote is expired.

Syntax: getdiffindays(date 1, date 2)

Parameters:

Return Type: Float

Example of getdiffindays():


Closedgetstrdate()

Returns the string representation of current date.

Syntax: String getstrdate()

Return Type: Boolean


Closedisleap()

Using this function will determine whether the date falls within a leap year. The function will return true if the year provided as a parameter is a leap year.

Example Use Case: Can determine if the date entered by a user is a valid date; or can be used when trying to calculate the total number of days in a given year.

Syntax: isleap(year_num)

Parameters:

Return Type: Boolean

Example of isleap():

Since the year 2008 was a leap year, the function returns True.


Closedisweekend()

This function determines whether a date falls within a weekend (Saturday or Sunday). The function will return true if the date provided as a parameter is a Saturday or Sunday.

Example Use Case: Can determine if the date entered by a user is a valid date.

Syntax: isweekend(date)

Parameters:

Return Type: Boolean

Example of isweekend():

The console will return either True or False.


Closedminusdays()

This function returns a date that is x days before the base date. Example Use Case: Can be used to set an expiration date of a quote.

Syntax: minusdays(date, num_of_days)

Parameters:

Return Type: Date

Example of minusdays():


Closedstrtodate()

Syntax: Date strtojavadate(String str, String format [, String timeZone])

This function is deprecated, and no longer supported. It converted data in String format to Date format.

Use strtojavadate() instead.


Closedstrtojavadate()

This function converts a string to a date and replicates Java behavior. Use this function instead of strtodate(), which is deprecated and no longer supported.

Syntax: strtojavadate(str, format)

Parameters:

Return Type: Date

Example of strtojavadate():


NOTES

RELATED TOPICS

Related Topics Link IconSee Also