Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Converting string to date object with Automation

I am currently utilizing Automaton for Jira LITE to handle incoming issues from emails. In the issue description, there is a date in a form of a string which I extract with a regex using match(). I can convert the string into a date object using .toDate. However, the converted object is not the correct date.

For example, one of the descriptions has a date of "September 3, 2019". I used .toDate("MMMM d, YYYY") to convert it to a date object with the correct format. I then format that date further to .format("d/MMM/yy"). It should spit out 3/Sep/19. The actual output is 30/Dec/18. When put it into a different format like yyyy-mm-dd, it spits out 2018-00-30. I've also tried changing the month in the description in July, same result. My guess is that my string format may cause Automation to read it incorrectly. 

Could this be related to how I've extracted the string via regex from the description? Should I try formatting the extracted string in a certain way so Jira/Automation can read it correctly? 

1 answer

1 accepted

2 votes
Answer accepted
Nick Menere Community Leader Aug 11, 2019

Hi Hieu,

I think we may need to break this down step by step. Use a log action or add comment with the following:

Parse: {{description.match("regex")}}
Date: {{description.match("regex").toDate}}
Date Format: {{description.match("regex").toDate.as("d/MMM/yy"}}

 

That should hopefully show us where it is breaking.

Cheers,

Nick

Hey Nick,

Thanks for replying.

Here is my output with the regex pulling "July 3, 2019" - 

Parse: July 3, 2019
Date: 
Date Format:

 I believe .toDate requires you to match the format of the string which is why I used .toDate("MMMM d, yyyy") to get an output for that function. Else, it comes up empty as you can see above. 

Like Cat W likes this

I figured out what I did incorrectly - 

 

Seems like there is a difference between YYYY and yyyy when formatting the year for turning a string into a date object. 

.toDate("MMMM d, yyyy") was what I needed to use.

Like Cat W likes this

@Nick Menere 

I'm effectively trying to do the same as Hieu here. However, when doing so, I'm only getting the following back:

Parse: June

Date:

Date Format:

 

Here's what I have in my automation:

Parse: {{issue.description.match("(January|February|March|April|May|June|July|August|September|October|December) (\d{2}), (\d{4})$")}}

Date: {{issue.description.match("(January|February|March|April|May|June|July|August|September|October|December) (\d{2}), (\d{4})$").ToDate}}

Date Format: {{issue.description.match("(January|February|March|April|May|June|July|August|September|October|December) (\d{2}), (\d{4})$").toDate.as("yyyy/MM/dd")}}

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