Choose where you’d like to start



The subMonth() function takes dateTimeValue and numberOfMonths as arguments. It returns the dateTimeValue after subtracting the specified number of months from it. The date-time value will be returned in the format specified in Application Settings.

Note :

This function will consider the number simply in terms of months. Therefore, the number of days being subtracted could vary for different date-time values. For example, 01-Jan-2019 to 01-Feb-2019 and 01 Feb-2019 to 01-Mar-2019 will be considered 1 month each, although the number of days in each case is different.

Return Type

  • Date-Time


<variable> = <dateTimeValue>.subMonth( <numberOfMonths> );


<variable> = subMonth( <dateTimeValue>, <numberOfMonths> );
ParameterDescriptionData type
<variable>Variable which will contain the returned date-time value.DATE-TIME

The date-time value from which the specified number of months will be subtracted.

The date-time value can be specified without a time value, in which case 00:00:00 will be taken as the default time value.

If the hour value is specified as 24 or more, the date-time value be reset to 00:00:00. If the minutes value is specified as 60 or more, the mm:ss value will be reset to 00:00, if the seconds value is specified as 60 or more, the ss value will be reset to 00.

A runtime error will be encountered if:

  • the hour value, or minute value, or second value, is specified in more than 2 digits
  • the date value exceeds the number of days in that month.
  • an incorrect month value is specified.
  • the year value has more than 4 digits.

Refer this help document to learn about the supported date-time formats.


The number of months to be subtracted from dateTimeValue.

A negative number will add the specified number of months to. dateTimeValue



currentDate = '01-Jan-2019';
newDate = currentDate.subMonth(1);         // returns '01-Dec-2018 00:00:00'

Get Started Now