# Sync DateTime Field in JIRA with Date Field in Zendesk

**URL:** <https://community.exalate.com/t/sync-datetime-field-in-jira-with-date-field-in-zendesk/4281>\
**Category:** General Questions\
**Tags:** onpremise-jira, zendesk, migrated\_question\
**Created:** [November 4, 2024, 6:44am UTC](https://community.exalate.com/t/sync-datetime-field-in-jira-with-date-field-in-zendesk/4281 "2024-11-04T06:44:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 6:44am UTC](https://community.exalate.com/t/sync-datetime-field-in-jira-with-date-field-in-zendesk/4281/1 "2024-11-04T06:44:35Z")

</div>

_Originally asked by Spencer Johnson on 17 July 2020 [(original question)](https://oldcommunity.exalate.com/questions/11340866)_

* * *

Hi I am trying to sync a datetime field in Jira with a date field in zendesk (bi-directionally) since Zendesk doesnt support date time fields.

Ideally in the future I would like to sync the “Time” portion as maybe a text field in zendesk but for now I just want the date to set the datetime in JIRA (I am okay if it always sets a default time as long as the date is correct)

Here is my current setup:

JIRA Outgoing Sync:

```auto
replica.customFields."Outage Start Time" = issue.customFields."Outage Start Time" 

```

JIRA Incoming Sync:

```auto
issue.customFields."Outage Start Time".value = replica.customFields."Outage Start Time"?.value 

```

Zendesk Outgoing Sync:

```auto
replica.customFields."Outage Start Time" = issue.customFields."Outage Start Time" 

```

Zendesk Incoming Sync:

```auto
issue.customFields."Outage Start Time".value = replica.customFields."Outage Start Time"?.value

```

Its currently syncing back and forth but for some reason the datetime value in Jira is the day before the date in zendesk.

Syncing from Jira to zendesk sets the proper date value but syncing from zendesk to Jira doesnt.

For example,

Date in Zendesk is changed to 16/Jul/20

DateTime in JIRA = 15/Jul/20 5:00 PM

* * *

#### Comments:

> **André Leroy-Beaulieu Castro commented on 01 September 2020**
>
> > Hi Spencer,
> 
> Could it be that the date internally in Jira is in a different timezone than zendesk? Because the datetime is sent as a timestamp and the Jira interprets it according to it’s timezone, so if there’s an hours difference that makes it seem like its the day before in Jira then that’s how it will be set.
> 
> Thanks,
> 
> André

> **Spencer Johnson commented on 08 October 2020**
>
> > André Leroy-Beaulieu Castro I got the fields working but I am trying to convert a string date in EST time to a date (timestamp) in PST time but am running into issues
> 
> Do you know how to convert a string representing a date (ie. ‘2020-10-25-11:45:00’) in EST to a timestamp in PST so I can set it in JIRA.
> 
> Zendesk is in EST but JIRA is in PST

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 6:44am UTC](https://community.exalate.com/t/sync-datetime-field-in-jira-with-date-field-in-zendesk/4281/2 "2024-11-04T06:44:36Z")

</div>

_Answer by Spencer Johnson on 09 October 2020_

Here is how I ended up synching a Date/Time field in JIRA (in PST) with a text field in Zendesk (representing a date time value entered in EST)

## Fields

**Zendesk Field:** “Outage Start Date” (Text field)

**JIRA Field:** “Outage Start Time” (Datetime field)

## Example

\*\*Entered in Zendesk:\*\*07/11/2020 11:30:00 PM

\*\*Value in JIRA:\*\*11/Jul/20 8:30 PM

## Zendesk

#### Zendesk Outgoing Sync:

```auto
replica.customFields."Outage Start Date" = issue.customFields."Outage Start Date" 

```

#### Zendesk Incoming Sync:

```auto
// ======= Date CF ===============
import java.text.SimpleDateFormat
import java.text.DateFormat
import java.util.Date
import java.util.TimeZone

 // Date Sync Function
def convertDateTimeToString(issueCustomField){
    def dateString = issueCustomField?.value;
    if (dateString) {
        def date = new Date(dateString.getTime())
        SimpleDateFormat dateFormat = new SimpleDateFormat( "MM/dd/yyyy hh:mm:ss a")
        dateFormat.setTimeZone(TimeZone.getTimeZone("US/Eastern"))
        if (date != null) {
            String dt = dateFormat.format(date)
            if (dt != null) {
                return dt;
            }
        }
    }
}

def outageStartTime = convertDateTimeToString(replica.customFields."Outage Start Time")
if (outageStartTime != null){
    issue.customFields."Outage Start Date".value = outageStartTime
}

```

## JIRA

#### Jira Outgoing Sync:

```auto
replica.customFields."Outage Start Time" = issue.customFields."Outage Start Time"

```

#### Jira Incoming Sync:

```auto
// ======= Date CF ===============
import java.text.SimpleDateFormat
import java.text.DateFormat
import java.util.Date
import java.util.TimeZone

def convertToDateTime(replicaCustomField){
    def dateString = replicaCustomField?.value
    DateFormat formatter= new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a")
    formatter.setTimeZone(TimeZone.getTimeZone("US/Eastern"))
    if (dateString != null) {
        def date = formatter.parse(dateString)
    
        // Set the formatter to use a different timezone 
        formatter.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"))
        def dt = formatter.format(date)
        def date2 = formatter.parse(dt);
        def ts = date2.toTimestamp()
        if (ts != null) {
            return ts
        }  
    }
}

def outageStartTime = convertToDateTime(replica.customFields."Outage Start Date")
if (outageStartTime != null){
    issue.customFields."Outage Start Time".value = outageStartTime
}

```

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 6:44am UTC](https://community.exalate.com/t/sync-datetime-field-in-jira-with-date-field-in-zendesk/4281/3 "2024-11-04T06:44:38Z")

</div>

_Answer by Shaleen Kukreti on 15 June 2023_

Spencer Johnson I used your code, but I am getting the below error

The only difference if that I want to Sync from ZD→ Jira(cloud) only and Date is Zendesk is “Date picker”

I posted more details [here](https://community.exalate.com/questions/58502806/sync-datetime-field-in-zd-with-date-field-in-jira)

 ![image2023-6-14_12-19-47.png](https://europe1.discourse-cdn.com/flex018/uploads/exalate1/original/1X/1eab3af9287468e952b554df71b0bc522d28a527.png)

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 6, 2024, 6:45am UTC](https://community.exalate.com/t/sync-datetime-field-in-jira-with-date-field-in-zendesk/4281/4 "2024-11-06T06:45:27Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
