|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
VB Date Computation
Given a year, a month, week of month and day of week, how can I figure out the exact date?
eg: Year = 2003 Month = December Week Of Month = 4 Day Of Week = 5 (Thursday) How do I figure out that the date is 25 Dec 2003 in VB 6.0? |
|
#2
|
||||
|
||||
|
You can do some pretty neat stuff using the dateAdd function. This should do the trick for what you need (there is a few problems with this code, for instance if you say month 11, week 1, day 1, it will give you a date in month 10 - try it, and you'll see what I mean)
Code:
iYear = 2003
iMonth = 11
'Change the month to an integer. You can use a switch
'statement for this.
iWeekOfMonth = 2
iDayOfWeek = 2
dtDate = iYear & "/" & iMonth & "/01"
'Get the date of the first day of the month
dtDate = DateAdd("ww", iWeekOfMonth - 1, dtDate)
'add the number of weeks to the date
iNumberMoreDays = iDayOfWeek - Weekday(dtDate)
'Calculate the number of days that should be added
dtDate = DateAdd("d", iNumberMoreDays, dtDate)
'Add the number of days
MsgBox (dtDate)
Hope this helps. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > VB Date Computation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|