Click here to Skip to main content
11,577,643 members (64,572 online)
Click here to Skip to main content

Tagged as

First day date in week based on particular date

, 29 Nov 2010 CPOL 13.3K 1
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.

Example:
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
 

    ' Calculate difference between specified date days of week and first day of week
    Dim Days As Integer = dayInWeek.DayOfWeek - CurrentCulture.DateTimeFormat.FirstDayOfWeek
 

    ' 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
 

    ' Substract difference of days from specified date
    Return dayInWeek.AddDays(-Days)
End Function

License

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

Share

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    Rant Rant    Admin Admin   

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

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