Allow more date input formats

Bradley Ross
Tera Guru

There are lots of acceptable ways to write a date (depending on your locale). What methods do you use to allow your users to enter a date in multiple formats in a field and have it get saved in a standard format? I love how I can type almost anything into Excel and have it get interpreted correctly as a date. That doesn't happen in ServiceNow. Am I missing something?

1 ACCEPTED SOLUTION

You do not want to spend time on a solution that already exists. I was able to change my date formatting in my profile to be MM-DD-YYYY, then type in a date into a date field (e.g.: 02-14-2016) and it shows up correctly when you select the picker. Try it yourself:



1. Go to your profile.


2. Select a date format that is different than what you have as your default date format.


3. Go to a form that has a date field.


4. Enter the date in the format you selected from step 2.


5. Tab away from the field.


6. Choose the date picker.



Since every user can be set to use a different format, you can probably work with your Identity Management or LDAP administrators to have the date format as part of the feed to ServiceNow. That way the user does not need to be responsible to change their settings themselves, and you can set the format based upon the preferred date format for the location the user is in.


View solution in original post

12 REPLIES 12

ghsrikanth
Tera Guru

This is pretty good requirement to enhance the date field, nice discussion to have. I am sure the way people write date in different countries are different -


In US, MM/DD/YYYY


In India, DD/MM/YYYY


But Servicenow provides us date picker, which I doubt Excel provides



Still to flow the discussion, we may do like this -



//Create an Array of Date Patterns which are acceptable in regexp


//And compare with the entered value and whatever pattern matches, then split the date string


//And construct Date object and assign back to the field


//For example I can give the code for pattern YYYY-MM-DD HH:MM:SS



var pattern = /\d\d\d\d-\d\d-\d\d (\d?\d):\d\d:\d\d/;


var value = g_form.getValue('dateField');


var verifyResult = pattern.exec(value);


if (verifyResult == null || verifyResult[0] != value) {


  g_form.showFieldMsg('dateField','Date must be entered in proper format, some example patterns are: list out patterns','error');


  return false;


} else {


  var dateString = g_form.getValue('dateField');


  var dateArray = startDateString.split(' ');


  var dayArray = dateArray[0].split('-');


  var timeArray = dateArray[1].split(':');


  var dateObject = new Date(dayArray[0], dayArray[1]-1, dayArray[2], timeArray[0], timeArray[1], timeArray[2]);


  g_form.setValue('dateField', dateObject);


  return true;


}




Any thoughts?


That's exactly the sort of function I'm thinking of. I'd like to find one rather than write one. Hopefully it would be something that is supported as part of the platform long term, but a supported 3rd party library could probably work, too. I was looking at the date input box available with Angular, for example.



https://material.angularjs.org/latest/demo/input



Notice how the date field on that page lets you enter a date in any of these ways:


  • 1-2-2016
  • 1/2/2016
  • 2016-1-2


Right now, if I have a date/time field in SN, my users have to user the date picker (lots of mouse clicks) or type it all in, including the time, in the exact format expected. I want to find something more forgiving and user friendly. The date picker in SN is some of my least favorite UI in the platform.



I'm reading that there are JS libraries that would allow my users to type "next Tuesday" in a field and the proper date would be stored.


https://github.com/abritinthebay/datejs


ccajohnson
Kilo Sage

It is unclear if you need methods to translate dates between formats, or just allow for different formats to display.



Service now allows for each user to set their date formatting preference in their profile. This means that whatever date you pick with the date-picker, will show up to you in that format.



I have done a lot of translating between formats, so if this is what you need, let me know so I can focus my reply accordingly.


My focus here is only on input. After the date is inputted, it should be stored in a standard format and then displayed for each user according to their individual preference. I think that already happens in SN.



What is missing is the ability to type in the date in 10 different formats and have a script the interprets it into a standard format.