Forums

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

Validate Date to be selected 1h prior to current date

Siddesh Mahajan July 11, 2023

Hi Team,

 

We are installed JMWE and we are looking to validate time part in Date and Time custom field where users are only allowed to select time 1 hr prior to the current date and time.

Ex: if your system is 2PM, users should select time between 1-2PM.

 

Thank you,

Siddesh

2 answers

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
July 11, 2023

Hi @Siddesh Mahajan 

you can create a Build-your-own Validator with a script like this:

!!issue.customfield_10201 && new Date(issue.customfield_10201) >= new Date().minusHours(1)

You'll need to replace customfield_10201 with the custom field ID of your Date/Time Picker custom field, which you'll find on the "Issue Fields" help tab of the script editor.

Siddesh Mahajan July 11, 2023

Hi @David Fischer , Thanks for the quick revert. Above mentioned code is not working. It creates tomorrow tickets and also 1 hr prior and later. I tried the below code also but to no luck.

 

!!issue.customfield_10203 && new Date(issue.customfield_10203) >= now.minusHours(1)

David Fischer
Community Champion
July 12, 2023

Hi @Siddesh Mahajan 

I forgot to prevent inputting a date later than now. Try this:

!!issue.customfield_10203 && new Date(issue.customfield_10203) >= new Date().minusHours(1) && new Date(issue.customfield_10203) <= new Date()
Siddesh Mahajan July 13, 2023

Hi @David Fischer , This worked thanks a lot

0 votes
David Fischer
Community Champion
July 11, 2023

Hi @Siddesh Mahajan 

should only the same day be accepted as well? I.e. only a date+time within the past hour?

Siddesh Mahajan July 11, 2023

Hi @David Fischer ,

 

Yes day must be same and time must be 1hr prior.

 

Thank you

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events