Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to subtract 15 months from date field value

Anil74
Tera Guru

Hi All,

We have two date fields A and B. A will auto populate with some date value from inbound integration, need to subtract this date with 15 months and populate it on B date field. How can we subtract A date field value with 15 months.

 

Thank you.

1 ACCEPTED SOLUTION

Abhishek Singh6
Kilo Guru

@Anil74, You can use gs.monthsAgo(15) function to get a 15 months before today's date. Please refer below SS for syntax :

 

Screenshot 2023-02-28 at 5.51.27 PM.png

You can use below code to get 15 months date before a given date (not today's date) :

 

var dateA = "2023-02-28 08:00:00";

var gdt = new GlideDateTime(dateA);
gdt.addMonths(-15);
gs.info(gdt.getDate());

Please mark helpful and accept solution if it helped you.

View solution in original post

3 REPLIES 3

Abhishek Singh6
Kilo Guru

@Anil74, You can use gs.monthsAgo(15) function to get a 15 months before today's date. Please refer below SS for syntax :

 

Screenshot 2023-02-28 at 5.51.27 PM.png

You can use below code to get 15 months date before a given date (not today's date) :

 

var dateA = "2023-02-28 08:00:00";

var gdt = new GlideDateTime(dateA);
gdt.addMonths(-15);
gs.info(gdt.getDate());

Please mark helpful and accept solution if it helped you.

Hi @Abhishek Singh6 , Thank you for quick reply. Its working.

OlaN
Tera Sage

Hi,

You can do this with a business rule, that runs when date A changes.

In the script you set date B by subtracting months from date A.

Example below:

 

var date1 = new GlideDateTime(current.getValue('some_date_A'));
date1.addMonthsUTC(-15);
current.setValue('some_date_B', date1.getValue());