Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add number of days to the creation date ?

Shivi Gupta June 17, 2020

Example:

Days = 3d 

Creation date = 17/06/2020

Due date = 22/06/2020 (exclude non working days )

2 answers

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 18, 2020 edited

@Shivi Gupta try to use this code:

import java.sql.Timestamp
import java.time.LocalDate
import java.time.ZoneId

Timestamp created = isssue.getCreated()
LocalDate createdDate = created.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
LocalDate result = createdDate;    
int addedDays = 0
int days = 3
while (addedDays < days) {
        
result = result.plusDays(1);
        if (!(result.getDayOfWeek() == DayOfWeek.SATURDAY || result.getDayOfWeek() == DayOfWeek.SUNDAY)) {
            
++addedDays;
        
}
    } 
Timestamp dueDate = 
Timestamp.valueOf(result.atStartOfDay());
issue.setDuedate(dueDate)

 

Shivi Gupta June 23, 2020

@Martin Bayer _MoroSystems_ s_r_o__ 

This code is throwing errors  :

 

Capture.JPG

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2020

@Shivi Gupta I tried to fix the code, give it a try, please

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 17, 2020

Can you elaborate on what context we're looking at here? Is it for a post-function? Which one?

Shivi Gupta June 18, 2020

I am trying it using script runner 

treimann99
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 5, 2020

Try something like this (+8 Hours in my case):

def date = new Date();
Calendar calendar = Calendar.getInstance();
date=calendar.getTime();
calendar.add(Calendar.HOUR_OF_DAY, 8)
if(calendar.get(Calendar.DAY_OF_WEEK)==7)
{
calendar.add(Calendar.DAY_OF_MONTH, 2)
}
if(calendar.get(Calendar.DAY_OF_WEEK)==1)
{
calendar.add(Calendar.DAY_OF_MONTH, 1)
}
date=calendar.getTime();

Suggest an answer

Log in or Sign up to answer