Skip to main content
Known Participant
January 31, 2024
해결됨

Date Field Entry uses first number entered as day, but I'd like it to be the month

  • January 31, 2024
  • 1 답변
  • 1499 조회

I've been searching to see if this was already answered on this forum or elsewhere, but I'm not finding it with the search terms I've tried...

 

When typing in the Date Fields, it takes the first number you enter as the day, instead of the month, but I would like the first number entered to be used as the month.

 

This wouldn't be a problem if I wanted it to display as MM/DD/YYYY, because it doesn't switch the order of the numbers, so even if I type 2/1/24 & it thinks 2 is the day, it still displays at DD/MM/YYYY & keeps it looking as 2/1/2024.... but I have a custom date format set to show it as "ddd - mmm d" - so if I type 2/1 thinking it will be Feb 1, it puts it as Jan 2.... ("Tue - Jan 2" instead of "Thu - Feb 1")

What can I do to make it so that when I type 2/1, it shows it as Feb 1, not Jan 2?

 

Thanks!

이 주제는 답변이 닫혔습니다.
최고의 답변: Nesa Nurani

 .


You can try this:

function reverseDate(str) {
 var regex = /^(\d{1,2})\/(\d{1,2})(\/(\d{2,4}))?$/;
 var match = str.match(regex);

 if (match) {
  var month = match[1];
  var day = match[2];
  var year = match[4] || '';

 if (year) {
  return day + '/' + month + '/' + year;} 
 else {
  return day + '/' + month;}} 
 else {
  return str;}}

event.value = reverseDate(event.value);

1 답변

BluSkye218작성자
Known Participant
January 31, 2024

This reply was originally to correct the typos in my original post, but I now have the option to edit my posts, so I edited my OP to remove the typos & this reply is no longer needed.

Nesa Nurani
Community Expert
Community Expert
January 31, 2024

It should be "Thu - Feb 1" not "Thu - Feb 2".

If you want to keep that format you could use a Validate script to reverse the order of numbers, for example if you enter 2/1 it will reverse, so the value would be 1/2.

BluSkye218작성자
Known Participant
January 31, 2024

Yes, that was a typo, thanks - I fixed it in my OP.

 

What is the script that would reverse the numbers? You're saying that there's a script that if I typed in 2/1 it would reverse it behind the scenes to be 1/2, then it would still outbook the format I put in for it to show "Thu - Feb 1"?