Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Compare date system with customl field date

Hello team

I tried to compare two date , first the date of system , second the date of a custom field so the problem 

is the date system return only day : 

the date of custom field timestamp return this : 

 

 

I need a help to compare the two dates 

I need help

WARN [runner.ScriptRunnerImpl]: DDP 10

 WARN [runner.ScriptRunnerImpl]: date de systeme Wed Dec 26 12:25:03 GMT+01:00 2018

 

Regards

1 answer

1 accepted

1 vote
Answer accepted

Hi @Karim Belhadj

 

Can you share the way that are you trying to compare the dates?

 

Adrián.

@Adrián Plaza [DEISER] of course , 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat

long createdDateTime = issue.created.getTime()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField IncidentStartField = customFieldManager.getCustomFieldObject("customfield_10801");
// String IncidentStart = issue.getCustomFieldValue(IncidentStartField)
long IncidentStart = (issue.getCustomFieldValue(IncidentStartField) as Date).getDate();
log.warn("DDP " + IncidentStart )
def systemDate = new Date()
log.warn ("date de systeme " + systemDate.getTime() )

def warrantyField = customFieldManager.getCustomFieldObjectByName("DDP")

def warranty = issue.getCustomFieldValue(warrantyField)
log.warn("ddp " + warranty)

 


if (IncidentStart < systemDate)

{

 

]

 

 

Regards

Hi @Karim Belhadj,

 

I made some modifications in your code and now looks like works fine:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat

//Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey("KANBAN-8")

long createdDateTime = issue.created.getTime()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField IncidentStartField = customFieldManager.getCustomFieldObject("customfield_10801");
// String IncidentStart = issue.getCustomFieldValue(IncidentStartField)
Date IncidentStart = (issue.getCustomFieldValue(IncidentStartField) as Date)
log.error("IncidentStart " + IncidentStart )
Date systemDate = new Date()
log.error ("date de systeme " + systemDate )

if (IncidentStart.getTime() < systemDate.getTime()){
return true
}else{
return false
}

 

Can you try?

 

I hope this help,

Adrián.

hi @Adrián Plaza [DEISER]  always the result of return = null

 

Sorry for that !

Can you help me why !!

Hi @Karim Belhadj,


Can you send me the log output?

yes 

@Adrián Plaza [DEISER]

 

this is the log 

2018-12-26 15:23:30,835 ERROR [runner.ScriptRunnerImpl]: IncidentStart 2018-12-27 00:00:00.0

2018-12-26 15:23:30,836 ERROR [runner.ScriptRunnerImpl]: date de systeme Wed Dec 26 15:23:30 GMT+01:00 2018

Hi @Karim Belhadj,

 

Can you try with this code and show me the log:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat

//Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey("KANBAN-8")

long createdDateTime = issue.created.getTime()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField IncidentStartField = customFieldManager.getCustomFieldObject("customfield_10801");
// String IncidentStart = issue.getCustomFieldValue(IncidentStartField)
Date IncidentStart = (issue.getCustomFieldValue(IncidentStartField) as Date)
log.error("IncidentStart " + IncidentStart +" and the time is "+ IncidentStart.getTime())
Date systemDate = new Date()
log.error ("date de systeme " + systemDate +" and the time is "+ systemDate.getTime())

if (IncidentStart.getTime() < systemDate.getTime()){
log.error("The incident start before the system date")
return true
}else{
log.error("The incident start after the system date")
return false
}

 

Adrián.

@Adrián Plaza [DEISER]   

this is the new log

2018-12-26 15:48:00,740 ERROR [runner.ScriptRunnerImpl]: IncidentStart 2018-12-27 00:00:00.0 and the time is 1545865200000

2018-12-26 15:48:00,741 ERROR [runner.ScriptRunnerImpl]: date de systeme Wed Dec 26 15:48:00 GMT+01:00 2018 and the time is 1545835680740

2018-12-26 15:48:00,741 ERROR [runner.ScriptRunnerImpl]: The incident start after the system date

Hi @Karim Belhadj,

Now it's working well, you can compare system date with custom field date, this is what do you need? I am right?

Adrián.

yes thank you very much 

 

Regards

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you