473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

FirstDayOfWeek

Hi, I'm wonder VB have som function to get First day of the week?

like I'm have

dim d1 as datetime=12/5/2007

d2 = firstweekday(d1) '=7/5/2007

thank you very much
May 12 '07 #1
3 2746
Here's the solution for you:

Private Function GetPreviousMonday(ByVal dt As DateTime) As String
Dim intWeekday As DayOfWeek = dt.DayOfWeek
Dim intSubtract As Integer = 0
Select Case intWeekday
Case 0 ' Sunday
intSubtract = -6
Case 1 ' Monday
intSubtract = 0
Case 2 ' Tuesday
intSubtract = -1
Case 3 ' Wednesday
intSubtract = -2
Case 4 ' Thursday
intSubtract = -3
Case 5 ' Friday
intSubtract = -4
Case 6 ' Saturday
intSubtract = -5
Case Else
Return "Unable to get day of the week"
End Select
Return dt.AddDays(intSubtract).ToString("MM/dd/yyyy")
End Function

Usage:

MessageBox.Show(GetPreviousMonday(#5/4/2007#))

I hope this helps,

--
Newbie Coder
(It's just a name)

"Thammarat charoenchai." <ap****@gmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi, I'm wonder VB have som function to get First day of the week?

like I'm have

dim d1 as datetime=12/5/2007

d2 = firstweekday(d1) '=7/5/2007

thank you very much

May 12 '07 #2
Shorter version, same as N. Coders, but less code.

Private Function GetStartOfWeek(selectedDate as datetime) as DateTime
Select Case SelectedDate.DayOfWeek
Case DayOfWeek.Sunday
return selecteddate.adddays(-6)
Case Else
Return selectedDate.AddDays(1 - selectedDate.DayOfWeek)
End Function

May 12 '07 #3
Thanks you very much. That's mean vb not have build in function for this .

i already coding.

Thanks again. :D
May 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
4
by: Lynn | last post by:
On a form I have Date_Start Date_End I have a new Date_Start1 Date_End1 which the use inputs. I need to validate that Date_Start1 and...
5
by: What-a-Tool | last post by:
Have a group of dynamically created text boxes in a calendar like grid. At the head of each column, the textbox is to contain the day of the week. Now I am using a Select Case statement to...
6
by: bojan.pikl | last post by:
Hi, I am making a calendar. It is costum made and I would like to have the ability to choose the first day (Monday or Sunday). I know for the firstDayOfWeek, but I can't change it. What should I do?
7
by: bojan.pikl | last post by:
Hi, I am making a calendar. It is costum made and I would like to have the ability to choose the first day (Monday or Sunday). I know for the firstDayOfWeek, but I can't change it. What should I...
3
by: boaring | last post by:
Hi, I wish to compare the sales figures over a period of time - but only FRIDAYS to see the effect of a project implemented on fridays? I have a DATE field & a SALES field among others.
2
by: Greg1028 | last post by:
I need help trying to write a query so I know when my employee are due for there semi-annual reviews based on there hire date.
1
MMcCarthy
by: MMcCarthy | last post by:
Access has a number of built-in functions which can be generally used in queries or VBA code. Some of the more common ones are: Note: anything in square brackets is optional Date Functions ...
4
by: khicon73 | last post by:
Hello All, I would like to calculate weeknumber and period from first day of the week (sunday) and last day of the week (saturday) and week number falls from 1 to 52 only. If week number >= 53 then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.