Skip to main content
Inspiring
June 20, 2023
Answered

How to auto-populate field with abbreviated day of week (SU, MO, etc.) based on entry in other field

  • June 20, 2023
  • 1 reply
  • 724 views

Hi!

 

I set up 7 fields:

 

FIELD02, FIELD03, FIELD04, FIELD05, FIELD06, FIELD07, FIELD08

 

to automatically populate with the days of the week:

 

SU, MO, TU, WE, TH, FR, SA

 

based on the user's entry in FIELD01, which is a "week ending date" formatted as "Date" and "mm/dd/yyyy".

 

I put the following formula into the 7 fields, with the -6 changing to -5, -4, -3, -2, -1, -0 for each field:

 

var s = this.getField("FIELD01").valueAsString;
if (s=="") event.value = "";
else {
var d = util.scand("mm/dd/yyyy", s);
d.setDate(d.getDate()-6);
event.value = util.printd("ddd", d);
}

 

Success, it worked! Except that the days of the week are displaying as:

 

Sun

Mon

Tue

Wed

Thu

Fri

Sat

 

Is there a way to make the auto-entries be 2 characters and all upper-case (SU, MO, TU, etc.)? I'm guessing it's the "ddd" that's doing it and I don't know if there's something to use in its place ("DD" didn't work). Or if it must be 3 characters can they all be upper-case?

 

Thank you so much! You all are so awesome in your help here!

Diane

This topic has been closed for replies.
Correct answer try67

It's a simple string manipulation:

 

event.value = util.printd("ddd", d).substring(0,2).toUpperCase();

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 20, 2023

It's a simple string manipulation:

 

event.value = util.printd("ddd", d).substring(0,2).toUpperCase();

Inspiring
June 20, 2023

Thank you, try67! To my rescue again! 🙂

 

After seeing the "simple" string manipulation 😉 that's needed I'm picturing a meme where someone has accidentally spit-sprayed their drink out over something they just read - in this case my simpler yet failed solution of using "DD". I can imagine that some posts might make members here chuckle (or spit-spray their drinks out).

 

I truly do appreciate your help here and your time spent doing it.

 

Have a wonderful day!

Diane

try67
Community Expert
Community Expert
June 20, 2023

I guess "simple" is a relative term... :=)

Anyway, you were not far off, but you didn't know that "dd" returns the full date in numbers, not in letters.

For future reference, "d" returns the short date in digits (without zero for values smaller than 10), "dd" returns the full date in two digits, "ddd" returns an abbreviated name (using the first three letters, in English), and "dddd" returns the full name.

But once you have that name you can manipulate it regardless of the options the printd method provides.