1. Registered User
Join Date
Jul 2012
Posts
8

## Date Function

I am working with a proprietary blend of Javascript and have no idea what I am doing.

What I am attempting to do is to take the value from a field (paydate) and convert it to a numerical form.

Next, I need to take a different value - from another field (ach adjust) - and add it to the original value to produce a new value (paydate + ach adjust)

The resulting numerical value needs to be converted to the corresponding day of the week.

Since the days can result in a large enough time frame, instead of the GetDay function, I used the GetDate function. Here is what I have:

var pd = paydate.getDate();

// coverts the value from the field "paydate" to a numerical value within
// the pd variable.

// converts the value from the field "clientMASTER_assoc_adjachdays" to
// a variable. This value is already in a numerical form.

// converts the value resulting from the addition of the values within the
// two variables, pd and adj, to the variable comp.

comp;

// outputs the variable.

This script would work perfectly if I just wanted a numerical value (from 1 to 31), but I need the actual day of the week (Sun..Mon...Tue...Wed...Thur...Fri...Sat). How can I accomplish this?

2. dateobject.getDay() returns 0-6 for Sun-Sat respectively.

3. Registered User
Join Date
Jul 2012
Posts
8
Great. But, if the value of the additional input is 0 or anything greater than 1 it messes with the result; (5 + 0 = 5), (5 + 2 = 7), (5 + 3 = 8)...

4. Before you use it do a &#37; 7 on it. Using a mod it will always be in range.

5. Registered User
Join Date
Jul 2012
Posts
8
I don't understand. Could you please put that into understandable context?

6. dateSub = dateSub &#37; 7

If your dateSub is < 7 nothing happens to it. If dateSub is larger than that it will be reduced to the 0-6 range.

7. Registered User
Join Date
Jul 2012
Posts
8
Given the code mentioned previously where would you add the datasub function?

8. Registered User
Join Date
Jul 2012
Posts
8
Bear in mind (in case I did not already mention it) that this is a proprietary blend of Javascript. In the situation that we previously discussed, I finished with the following code:

var pd = paydate.getDay();

// converts the value from the "paydate" field to an integer.

// converts the integer from the "clientMASTER_assoc_adjachdays" field to a variable.

// adds the two variables, pd and adj together, and converts the result to a variable.

comp = comp%6;

// constrains the results of the previous mathematical equation to a value of // less than or equal to 6.

var arDays = new Array("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday");

// opens an array of the days of the week (0=Sunday,1=Monday...)

var achd = arDays[comp];

//compares the results of the comp variable to the arDays array and converts the result to another variable; the day of the week.

achd;

//outputs the achd variable

... In case anyone else ever needs to know.

9. Make that
Code:
`comp = comp &#37; 7`
. The range will be from 0 thru 6. See messages 4 & 6 in this thread.

10. Registered User
Join Date
Jul 2012
Posts
8
Another "expert" advised me that I should instead use "comp = comp&#37;6". Sorry. I updated as per your recommendation.

11. He must live in a place where there are only six days in a week. <g> Glad to hear it works now.

12. Registered User
Join Date
Jul 2012
Posts
8
Well, the array does consist of only the numbers 1 - 6 (0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday). Could you please explain why you need a 7 for all of us poor, uneducated people?

13. Take any day of the month and note the day of the week. Now add or subtract 7, 14, 21, or 28. Won't it be the same day of the week?

Take any positive integer and divide it by seven. If you ignore the quotient and pay attention only to the remainder, how big can it get and how small can it get? If you chose 13, the remainder would be 6. Add 1 to it, 14 is evenly divisible by 7 so the remainder will be zero.

14. Registered User
Join Date
Jul 2012
Posts
8
I can't see any fault in your logic. Thanks, Wbport for explaining that.