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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginning of Week date

Status
Not open for further replies.

VBFOXDEV35

Programmer
Mar 26, 2001
77
US
All:
Just a curious question of how to do this.

I am writing a small application for a user, and they need to have the date textbox fill with the current startdate of the week.

For example, today is 10/09/2002, I want to have the textbox say 10/07/2002, Monday's date.

How would one go about doing this? I have a couple of ideas in mind, but I figure I would ask the experts before I started coding.

Thanks all.
Art
Art DeGaetano II
Software Developer, MOUS
 
? iif(dow(date()) <> 2,date()-dow(date()-2),date()) 'We all must do the hard bits so when we get bit we know where to bite' :)
 
Here is a function I use, it's not elegant, but it takes today's date, and keeps backing up until it hit the Monday of the week.

The CDAT variable equals the date parameter you want to pass it ,
Code:
FUNCTION findMondayofThisWeek
LPARAMATER 
Do While Alltrim(Upper(Cdow(CDAT)))!= &quot;MONDAY&quot;
		CDAT = CDAT - 1
enddo
ENFUNC
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Peping

?DATE()-(7-(DOW(DATE())))

This gives me Sunday
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Thank you all!!

I knew there was a combination of using the DOW and Date functions, I just needed to know the correct way to do it.

Thanks to all that replied!!!

Art Art DeGaetano II
Software Developer, MOUS
 
Mike,

Is it obvious that 7 will give Sunday as the first day of the week as VFP default?

VBFOXDEV35, following will return &quot;Monday&quot; for any given date expression:

SET FDOW TO 2
x=SET('FDOW')
?DATE()-DOW(DATE())+x

Peping
 
Peping

Is it obvious that 7 will give Sunday as the first day of the week as VFP default?

I thought you may have read the question wrong, since VBFOXDEV35 was asking for monday's date. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Hi !!
You must check, what is in Tools, Options, Regional, Weeks Starts On.
Monika Kind regards to you all from Warsaw !!!!!
 
Other useful date functions you may or may not know:

DATE()-DAY(DATE())
....this gives you the last day of the previous month
DATE()-DAY(DATE())+1
....this gives you the first day of the current month, so...
GOMONTH(DATE()-DAY(DATE())+1,-1)
....gives you the first day of the previous month

Stewart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top