I’m working on a project where I need to create Jira issues using the jira-python library. I’ve added a custom Date Time Picker field (customfield_10300) to my issues. But I’m having trouble setting its value when creating a new issue.
But it’s not working. The custom field isn’t being set correctly. Does anyone know the right format for setting a Date Time Picker field? I’ve tried different date formats, but nothing seems to work. Any help would be great!
I’ve encountered similar issues when working with custom fields in Jira. One thing to note is that Jira often expects datetime values in a specific format, typically milliseconds since the Unix epoch. Here’s an approach that has worked for me:
import time
# Convert your datetime to milliseconds
timestamp = int(time.mktime(datetime(2023, 5, 15, 14, 30).timetuple()) * 1000)
issue_details = {
'project': {'key': 'PRJ'},
'summary': 'Test issue',
'description': 'This is a test',
'issuetype': {'name': 'Bug'},
'customfield_10300': timestamp,
}
This method converts your datetime to a Unix timestamp in milliseconds, which Jira can interpret correctly. If this doesn’t work, you might need to check your Jira instance’s specific requirements or consult your Jira admin for the exact expected format.
I’ve dealt with this exact issue before, and it can be tricky. The key is to use the correct datetime format that Jira expects. In my experience, you need to use an ISO 8601 formatted string for Date Time Picker fields.
Try modifying your code like this:
from datetime import datetime
issue_details = {
'project': {'key': 'PRJ'},
'summary': 'Test issue',
'description': 'This is a test',
'issuetype': {'name': 'Bug'},
'customfield_10300': datetime(2023, 5, 15, 14, 30).isoformat() + '.000+0000',
}
The ‘.000+0000’ part at the end is crucial since it specifies milliseconds and timezone offset, which Jira requires. If you’re still having trouble, double-check that your custom field’s ID is correct for your Jira instance.