Wilder1626
asked on
VB6 = Week of the year in TextBox
Hello all
I'm trying to find a way to put in Text1 the week number if the year.
Ex:
Between Dec 30 2012 and January 5ft 2013, this = Week 1
Between Jan 6 2012 and January 12 2013, this = Week 2....
So when i load the form with my Text1, today, i would see 1 (Being week 1)
How can i do that.
Thanks again for your help
I'm trying to find a way to put in Text1 the week number if the year.
Ex:
Between Dec 30 2012 and January 5ft 2013, this = Week 1
Between Jan 6 2012 and January 12 2013, this = Week 2....
So when i load the form with my Text1, today, i would see 1 (Being week 1)
How can i do that.
Thanks again for your help
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
But if i do this, now i have week 1:
weird.
Dim iNumberOfTheWeek As Integer
iNumberOfTheWeek = DatePart("ww", Now() + 2)
MsgBox iNumberOfTheWeek
weird.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You don't want to add 2 to Now() because you are looking up the week number for 2 days later which is Jan 1st.
ASKER
Hi again.
Thank you so much both of you, again
all work great now.
Thank you so much both of you, again
all work great now.
You're welcome and I'm glad I was able to help.
Marty - MVP 2009 to 2012
Marty - MVP 2009 to 2012
Here is another, possibly the right way to obtain Week Of the Year
'Syntax for DatePart:
'DatePart (Interval, Date, [FirstDayOfWeek, [FirstWeekOfYear]] )
'The FirstWeekOfYear argument can have one of the following settings.
'2 - Week that has at least four days in the new year (complies with ISO standard 8601, section 3.17)
'1 - Week in which January 1 occurs (default)
'0 - First week of year specified in system settings
'Syntax for DatePart:
'DatePart (Interval, Date, [FirstDayOfWeek, [FirstWeekOfYear]] )
'The FirstWeekOfYear argument can have one of the following settings.
'2 - Week that has at least four days in the new year (complies with ISO standard 8601, section 3.17)
'1 - Week in which January 1 occurs (default)
'0 - First week of year specified in system settings
'iNumberOfTheWeek = DatePart("ww", Now(), vbMonday, 2)
'MsgBox iNumberOfTheWeek
'You can use GetLocaleInfo API to obtain FirstWeekOfYear Specifier
iNumberOfTheWeek = DatePart("ww", Now(), vbMonday, GetMyLocaleInfo(LOCALE_IFIRSTWEEKOFYEAR))
MsgBox iNumberOfTheWeek
Option Explicit
Private Declare Function GetLocaleInfo Lib "kernel32" _
Alias "GetLocaleInfoA" (ByVal Locale As Long, _
ByVal LCType As Long, ByVal lpLCData As String, _
ByVal cchData As Long) As Long
Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
Private Const LOCALE_IFIRSTWEEKOFYEAR As Long = &H100D 'first week of year specifier
Private Function GetMyLocaleInfo( _
ByVal LCType As Long _
) As String
Dim sReturn As String
Dim iRet1 As Long
Dim iRet2 As Long
Dim lpLCDataVar As String
Dim Pos As Integer
Dim Locale As Long
Locale = GetUserDefaultLCID()
iRet1 = GetLocaleInfo(Locale, LCType, lpLCDataVar, 0)
sReturn = String$(iRet1, 0)
iRet2 = GetLocaleInfo(Locale, LCType, sReturn, iRet1)
Pos = InStr(sReturn, Chr$(0))
If Pos > 0 Then
sReturn = Left$(sReturn, Pos - 1)
End If
GetMyLocaleInfo = sReturn
Exit Function
End Function
ASKER
Thanks eemit
This is also very good to know
This is also very good to know
ASKER
Open in new window