Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get First of week using Weekday() procedure.

Status
Not open for further replies.

BadCook

Technical User
Sep 7, 2009
71
US
I have been trying to get the number of the first day of the month using the Weekday() procedure.
I must be doing something wrong. Ccan anyone please show me an example?
 
You want to know the weekday for the first day of the month? If you have a date in a variable called 'DateField' then
Code:
Weekday ( DateSerial ( Year(DateField), Month(DateField), 1 ) )
will return

[blue]1 = Sunday[/blue]
[blue]2 = Monday[/blue]
etc.
 
how are you using this FUNCTION in your code?

What result do you get?

What result do you expect?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for replies guys.

Skip, I get error messages.
Having a year, say 2012, and a month, say October, I want to find what day of the week, from 1 to 7, the first dsy of the month falls on.
This is the first time I'm using this function and I'm a bit confused.
 
And your code, that was requested. Frankly, you did not answer ANY of my questions!

In addition to the answers to the formerly asked questions, what error message on what statement?



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip
Sorry I didn't give you all the information you wanted but I've succeded in working out the problem.
The code I came up with is: (first day of first week of a month) = Weekday(DateSerial((Year(Date,1,1))).
It works very well and gives me what I want.
Thanks again for your interest.
 
Hey BadCook! don't know what you cooked up but this would be correct for AnyDate...
Code:
Weekday(DateSerial(Year(AnyDate),month(AnyDate),1))

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
...which is what Golom originally posted for your benefit!

What ever happened?????

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
... Guess you just can't help making BadCook choices! Makes sense!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
BadCook said:
Weekday(DateSerial((Year(Date,1,1))).
It works very well and gives me what I want.

Which I find very surprising since it is syntactically incorrect and raises an error. Even a corrected version

[Blue]Weekday(DateSerial(Year(Date),1,1))[/blue]

just gives you the weekday for January first of the current year. Given that your first post mentioned October as the month of interest, this is clearly not "giving you what you want.
 
Sorry for the confusion guys.
My bad.
What I want and finally got was something that gives me the weekday number for day 1 of any month of any year.

The following works well.
Example: Weekday("5/2013") = 4.
Thanks to all for your interest.

BTW, Id like to make a contribution to this site. How do I go about it?
How do I go about it?
 
Search for [red]Donate[/red] on this page.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top