Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Sep 19, 2000

Finding the First Date of a Week

Question:
If I have the number of a given week of a year, how can I get the date of the first day of that week? For example, I want the date of Sunday of the 5th week in 1999.

Answer:
There's not a built-in function that can do all the work for you on this one. However, you can do this:

  1. The first day of the year is always January 1st. (duh, right?) That will fall on some day of the week, which you can determine by using the Weekday function. Weekday will return you a number from 1 to 7 indicating what day of the week that date is.
  2. If you want to go to the beginning of the 5th week, you need to add (4 x 7) days to January 1st. The DateAdd function can do this and return you the date that the fifth week of the year starts on.
  3. Once you have that date, you can simply check the Weekday value of it to determine how many more days until you hit Sunday.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date