Click here to Skip to main content
12,996,849 members (129,103 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 24 Nov 2010

First day date in week based on particular date

, 29 Nov 2010
Rate this:
Please Sign up or sign in to vote.
Find first day of week containing given date
This function identifies the first day of week based on a particular date.

Sending 01.01.2010 will return 28.12.2009.

M | T | W | T | F | S | S
28  29  30  31   1    2    3

First date in same week as 01.01.2010 date, is 28.12.2009.

''' <summary>Returns first day date in week based on specified date.</summary>
Private Function FirstDateOfWeek(ByVal dayInWeek As Date) As Date
<br />
    ' Calculate difference between specified date days of week and first day of week
    Dim Days As Integer = dayInWeek.DayOfWeek - CurrentCulture.DateTimeFormat.FirstDayOfWeek
<br />
    ' Add day difference to number of days in week then devide sum with days in week, reminder is number of days we need to substract
    Days = (7 + Days) Mod 7
<br />
    ' Substract difference of days from specified date
    Return dayInWeek.AddDays(-Days)
End Function


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Enver Maroshi
Croatia Croatia
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralGood tip Pin
Abdul Quader Mamun16-Dec-10 9:29
memberAbdul Quader Mamun16-Dec-10 9:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 29 Nov 2010
Article Copyright 2010 by Enver Maroshi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid