Click here to Skip to main content
Click here to Skip to main content

Tagged as

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.
 
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

Comments and Discussions

 
GeneralGood tip PinmemberAbdul 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 | Mobile
Web01 | 2.8.140814.1 | Last Updated 29 Nov 2010
Article Copyright 2010 by Enver Maroshi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid