WEEKDAY()

E

Epinn

Regarding WEEKDAY(), I read that problems can occur if dates are entered as text.

Based on this, it is understandable that =WEEKDAY(2/14/2008) returns a wrong result (7). This is because general format is same as text.

If I enter =WEEKDAY(DATE(2008,2,14)), I get the correct result (5).

Okay, so far. What I don't understand is the following.

I click A1 and key in 2/14/2008, then in A2, I key in =WEEKDAY(A1). I also get the correct result (5).

The way I enter 2/14/2008 to A1 is exactly the same as I enter 2/14/2008 *directly* to the formula. It amazes me that referencing A1 in WEEKDAY() gives me the correct answer whereas keying it in as part of the formula won't work.

Comments welcome.

Epinn
 
B

Bob Phillips

But the difference is that when you key 21/4/2008 into cell A1, Excel
recognises it as a date and converts it to an underlying value of 39559,
which it presents/formats as that date.

When you enter it into a function, the function treats it as its argument,
and says that it is invalid as it expects a number (the true underlying
value). 21/4/2008 is not a number here, so it errors.

If you want to enter the date into the WEEKDAY function, you have to force
it into a number, either using another function such as you did with DATE,
or coerce it directly, like

=WEEKDAY(--"21/4/2008")

or my preferred format of

=WEEKDAY(--"2008-04-21")

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

Regarding WEEKDAY(), I read that problems can occur if dates are entered as
text.

Based on this, it is understandable that =WEEKDAY(2/14/2008) returns a wrong
result (7). This is because general format is same as text.

If I enter =WEEKDAY(DATE(2008,2,14)), I get the correct result (5).

Okay, so far. What I don't understand is the following.

I click A1 and key in 2/14/2008, then in A2, I key in =WEEKDAY(A1). I also
get the correct result (5).

The way I enter 2/14/2008 to A1 is exactly the same as I enter 2/14/2008
*directly* to the formula. It amazes me that referencing A1 in WEEKDAY()
gives me the correct answer whereas keying it in as part of the formula
won't work.

Comments welcome.

Epinn
 
M

MartinW

Hi Bob,

Can you also explain another one along similar lines.
If I put todays date 09/09/2006 in A1.
Then in A2 I put =MONTH(A1) and I get 9 which is good.
I then format A2 as mmmm and I get January. What gives??

Confused
Martin
 
B

Bob Phillips

Again it is because the underlying values of dates are just numbers. As I
said to Epinn, the value stored in a date of 21/4/2008 is 39559.

Now when you do a =MONTH(A1) in A2, you are not really returning a date, but
a simple month number (9 in the case quoted). But, because it is a number,
if you do date type things on it, Excel will not complain, it will just work
on whatever date that number resolves to. As a date is stored as the number
of days since 1st January 1900, the value of 9 will be treated as 9th Jan
1900, so if you format it as mmmm, you get January. Format it as dd/mm/yyyy,
and see what I mean.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
E

Epinn

Bob,

Glad I still caught you this late. Thank you for enlightening me.

<<21/4/2008 is not a number here, so it errors.

If it gives me an error, then I know. The problem is it returns "7" instead of "5" in my other example. That's very misleading and dangerous.

=WEEKDAY(--"21/4/2008") gives #VALUE!
=WEEKDAYS(--"4/21/2008") gives 2.

So, I understand why you prefer =WEEKDAY(--"2008-04-21").

But I prefer "/" to "-" and I tested it. I am glad that "/" works too.

My preference will be =WEEKDAY(--"2008/4/21").

I assume "--" above is the same as "--" in SUMPRODUCT(). Please confirm. Can't find double negating in Help.

I find date functions may be as confusing as SUMPRODUCT().

Will see.

Epinn

But the difference is that when you key 21/4/2008 into cell A1, Excel
recognises it as a date and converts it to an underlying value of 39559,
which it presents/formats as that date.

When you enter it into a function, the function treats it as its argument,
and says that it is invalid as it expects a number (the true underlying
value). 21/4/2008 is not a number here, so it errors.

If you want to enter the date into the WEEKDAY function, you have to force
it into a number, either using another function such as you did with DATE,
or coerce it directly, like

=WEEKDAY(--"21/4/2008")

or my preferred format of

=WEEKDAY(--"2008-04-21")

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

Regarding WEEKDAY(), I read that problems can occur if dates are entered as
text.

Based on this, it is understandable that =WEEKDAY(2/14/2008) returns a wrong
result (7). This is because general format is same as text.

If I enter =WEEKDAY(DATE(2008,2,14)), I get the correct result (5).

Okay, so far. What I don't understand is the following.

I click A1 and key in 2/14/2008, then in A2, I key in =WEEKDAY(A1). I also
get the correct result (5).

The way I enter 2/14/2008 to A1 is exactly the same as I enter 2/14/2008
*directly* to the formula. It amazes me that referencing A1 in WEEKDAY()
gives me the correct answer whereas keying it in as part of the formula
won't work.

Comments welcome.

Epinn
 
M

MartinW

Thanks Bob, of course it is I should have seen that...duh!
So to get a return of September I can see a way of doing it by
hiding the month cell and a Vlookup table somewhere out of the
way and using a Vlookup in A2. Is there a simpler method?

Thanks again
Martin
 
S

SteveW

Because weekday(21/4/2008) does give an error
as it treats 21/4/2008 as 21/4 divided by 2008 - nearly 0
ie 0/1/1900 in date terms
Odd but thats what's happening

Steve
 
B

Biff

When you enter it into a function, the function treats it as its argument,
and says that it is invalid as it expects a number (the true underlying
value). 21/4/2008 is not a number here, so it errors.

Actually, the formula does not "error" but calculates properly.

The argument: 2/14/2008 is the equivalent of:

2 divided by 14 divided by 2008

which equals: 0.0000711439954467843

Since WEEKDAY only works with integers Excel truncates the value to 0.

Weekday( 0 ) is actually 12/31/1899 which is a Saturday or weekday 7 when
the return_type used is 1 or omitted.

This is another Excel nuance. The date serial system doesn't start until day
1 which is 1/1/1900 yet you can calculate a date to be 1/0/1900. Excel
treats the 0th day of the month as the last day of the previous month.
That's how we end up with 7 as the result of the Weekday function.

Biff
 
S

SteveW

the N and the T on my keyboard are sicky sorry sTicky
So I meant to write "weekday(21/4/2008) doesN'T give an error"

Steve
 
R

Ragdyer

Probably the reason 21/4/2008 doesn't work for you is because your regional
settings aren't set-up as d/m/y, BUT as m/d/y.

It *would* work on Bob's machine because he probably has the European short
date set-up in his regional settings.

And of course, 2008/04/21 should work *everywhere*, since it's recognized as
international.
--
Regards,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
Bob,

Glad I still caught you this late. Thank you for enlightening me.

<<21/4/2008 is not a number here, so it errors.

If it gives me an error, then I know. The problem is it returns "7" instead
of "5" in my other example. That's very misleading and dangerous.

=WEEKDAY(--"21/4/2008") gives #VALUE!
=WEEKDAYS(--"4/21/2008") gives 2.

So, I understand why you prefer =WEEKDAY(--"2008-04-21").

But I prefer "/" to "-" and I tested it. I am glad that "/" works too.

My preference will be =WEEKDAY(--"2008/4/21").

I assume "--" above is the same as "--" in SUMPRODUCT(). Please confirm.
Can't find double negating in Help.

I find date functions may be as confusing as SUMPRODUCT().

Will see.

Epinn

But the difference is that when you key 21/4/2008 into cell A1, Excel
recognises it as a date and converts it to an underlying value of 39559,
which it presents/formats as that date.

When you enter it into a function, the function treats it as its argument,
and says that it is invalid as it expects a number (the true underlying
value). 21/4/2008 is not a number here, so it errors.

If you want to enter the date into the WEEKDAY function, you have to force
it into a number, either using another function such as you did with DATE,
or coerce it directly, like

=WEEKDAY(--"21/4/2008")

or my preferred format of

=WEEKDAY(--"2008-04-21")

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

Regarding WEEKDAY(), I read that problems can occur if dates are entered as
text.

Based on this, it is understandable that =WEEKDAY(2/14/2008) returns a wrong
result (7). This is because general format is same as text.

If I enter =WEEKDAY(DATE(2008,2,14)), I get the correct result (5).

Okay, so far. What I don't understand is the following.

I click A1 and key in 2/14/2008, then in A2, I key in =WEEKDAY(A1). I also
get the correct result (5).

The way I enter 2/14/2008 to A1 is exactly the same as I enter 2/14/2008
*directly* to the formula. It amazes me that referencing A1 in WEEKDAY()
gives me the correct answer whereas keying it in as part of the formula
won't work.

Comments welcome.

Epinn
 
M

MartinW

Yeah tried that RD but I'm cocatenating the result and that
returns a value of 38969 instead of september for the cell
even though it displays as september. The Vlookup works
fine so I might just stick with that.

Thanks for postig
Martin
 
R

Ragdyer

Try this to concatenate:

C1 contains the text,
20 days in

SO ...

=C1&" "&TEXT(A2,"mmmm")
 
B

Bob Phillips

Hi Epinn,

The "--" is exactly the same as its usage in SUMPRODUCT, it is coercing into
a numeric.

As RD says the second version of that works for you, but fails for me is
because we have different date settings, yours are American, mine are
European.

The purpose of using the date in the format yyyy-mm-dd or yyyy/mm/dd is to
remove ambiguity (10/09/2006 is 9th Oct to you, it's 10th Sep to me). I
prefer the use of the "-" separator because that is part of the ISO
standard.

No, you are just trying to understand properly so that you can use more
effectively. Nothing wrong with that. I answered a post on another forum
where a guy gave totally misleading information about SUMPRODUCT as if it
were gospel. It didn't affect the solution, which worked, but should the OP
have tried to take it further, he would really have gotten confused. I don't
see that happening to you.

And if you think dates are confusing, just pity us developers who work in
both markets, catering for all forms can be really challenging.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
E

Epinn

Thank you all. This has been very educational. I have a few comments.
settings aren't set-up as d/m/y, BUT as m/d/y.

Good point, RD.

If I key 9/9/2006 into A1, what formula do I use in A2 to get 38969. Please advise.

If I key 9/9/2006 into A1, I think I can reference A1 directly in the above formula, instead of entering =A1 in A2 and then using A2 in the above formula.

Don't think I want to agree with this. I key in =WEEKDAY(0) into a cell, I get 7-Jan-00. Don't know why and not sure if we are talking about the same thing.

=MONTH(0) yields 1-Jan-1900. In both cases, we never got back to 1899.

=WEEKDAY(--"1899/12/31") gives an error #VALUE! which makes sense as the date system starts at 1/1/1900.

Talking about 1899 makes me feel very old ;) but all this is very interesting. Please keep the date talk going.

Next I have to analyze the formula for "last workday of the current month." This formual is three-line long and uses EOMONTH(). Looks tough. If it gets too confusing, I'll just use it without understanding it. There is a shorter formula but uses "holidays" as part of the syntax. (Holidays is not a function.)

Epinn

Hi Epinn,

The "--" is exactly the same as its usage in SUMPRODUCT, it is coercing into
a numeric.

As RD says the second version of that works for you, but fails for me is
because we have different date settings, yours are American, mine are
European.

The purpose of using the date in the format yyyy-mm-dd or yyyy/mm/dd is to
remove ambiguity (10/09/2006 is 9th Oct to you, it's 10th Sep to me). I
prefer the use of the "-" separator because that is part of the ISO
standard.

No, you are just trying to understand properly so that you can use more
effectively. Nothing wrong with that. I answered a post on another forum
where a guy gave totally misleading information about SUMPRODUCT as if it
were gospel. It didn't affect the solution, which worked, but should the OP
have tried to take it further, he would really have gotten confused. I don't
see that happening to you.

And if you think dates are confusing, just pity us developers who work in
both markets, catering for all forms can be really challenging.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
S

SteveW

=weekday(d/m/y) or (m/d/y or whatever)
it treats it like a number on mine exactly the same results
as if I type =d/m/y ... in a cell and have =weekday(cell)

They all act as (a/b)/c for me
Now if they were in ""'s that might be different

Steve
 
E

Epinn

Steve,

I heard you. But we were discussing WEEKDAY() *with coercing* i.e. including double negating in the formulae. Do I say it right, Bob? Try to include double negating in both of your formulae and see if you get an error for either one. Like Bob and RD said, the error depends on your date default system for your region.

Epinn

=weekday(d/m/y) or (m/d/y or whatever)
it treats it like a number on mine exactly the same results
as if I type =d/m/y ... in a cell and have =weekday(cell)

They all act as (a/b)/c for me
Now if they were in ""'s that might be different

Steve
 
B

Bob Phillips

Thank you all. This has been very educational. I have a few comments.
Please advise.

=A1 and format as General. As we said the underlying value of a date is just
the number of days since 1st Jan 1900, so it is already that number. You
just format it to see it.

Correct
omitted.

You may not want to, but Biff is right. 1st Jan 1900 was a Sunday, the 31st
Dec 1899 was a saturday, which is day 7 to WEEKDAY. You get 7-Jan-00 because
it is formatted that way, the underlying value is 7.

No, it yields 1. You just have it formatted as a date. A month number is not
a date, it is the ordinal value of the month within the year.

It does, as Excel "knows" that is not a date in its view of the world, but
you can fool it

=WEEKDAY(--"1900/01/01"-1)

returns 7.

Again as Biff, this is another nuance of Excel.

It would be nice if Norman Harker joined the discussion. He has made the
study of dates a speciality.
(Holidays is not a function.)

How about

=WORKDAY(DATE(YEAR(TODAY()),MONTH(TODAY())+1,0),-1)

or without the ATP function

=DATE(YEAR(A1),MONTH(A1)+1,0)-(MAX(0,WEEKDAY(DATE(YEAR(A1),MONTH(A1)+1,0),2)
-5))

Epinn

news:#[email protected]...
 
E

Epinn

Yes, without quotes nor double negating, I don't get an error either for both formats.

Epinn

=weekday(d/m/y) or (m/d/y or whatever)
it treats it like a number on mine exactly the same results
as if I type =d/m/y ... in a cell and have =weekday(cell)

They all act as (a/b)/c for me
Now if they were in ""'s that might be different

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top