NewBie Help: DateDiff function

Keroleen

Freshman
Joined
Sep 15, 2003
Messages
36
Purpose:

I need to output to a textbox the year and the week of year.
The user will pick a date out of a DateTimePicker tool. The systsem should be able to output the year and the weekofyear.

How do I make the program calculate the weekofyear based on the current year and have a 'counter' so every subsequent year (2004,2005 etc etc) it will know, is one of the dates to be compared.

There will be no date earlier than 1999.
The reset date should be Jan 1 of each year

I am able to calculate the number of weeks since 1999 with this code:

'Week_Of_Year = DateDiff("d", FirstDay, PickedDate, FirstDayOfWeek.Saturday) / 7


Where FirstDay is a constant 12/29/1999
Where PickedDate is the date where the user picks using the DateTimePickerTool


Thank you and very much appreciated.:confused:
 
Did I understand correctly ?

You need to display th week of the year and the year of the day selected by the user??

So if the user chose January 1 2002 then you would display
1 for the week of year and 2002 for the year ???

If not what would you return in this case and explain why please...
 
Yes that is right: For example if the user clicked January 1, 2002 in the DateTimePicker. It should display 20021


The first available date is : Dec 18/99 (no date will be before this).
Im able to calculate the weeks SINCE this date but how do I calculate for just the weeks in the specific year.

As well how do you reset a counter(perhaps) so that it goes back to week 1 once they hit Jan 1 of a new year

example: 20021 (january 1, 2002)
20031 (january 1, 2003)


mmmmm...guess its kinda confusing but i hope this is more clear?
Thanks
 
Sorry for taking so long to respond but i am pretty busy these days.

As for the year it will DateTimePicker1.Value.Year

As for the week of year, you can first get the day of the year and then divide it by seven .. i think that would do the trick.

To get the day of year..
DateTimePicker1.Value.DayofYear

To get which week
DateTimePicker1.Value.DayofYear / 7 and retrieve only whole numbers.

Hope this helps,
 
Meyhar:

Thanks for the help :D...but actually that idea didnt work
This did it


Week_Of_Year = (DateDiff("ww", FirstDay, PickedDate, FirstDayOfWeek.Saturday, FirstWeekOfYear.Jan1) - 1 / 7)

'reset Week_Of_Year = 0 at the beginning of the year. Start counter again at 0-52
If Week_Of_Year > 52 Then
Week_Of_Year = 1
NewYear = NewYear.ToString("dd-MMM-yy")
Week_Of_Year = (DateDiff("ww", FirstDay, PickedDate, FirstDayOfWeek.Saturday, FirstWeekOfYear.Jan1) - 1 / 7) Mod 52
Year = DatePart("yyyy", PickedDate)
txt_week.Text = (Year) & (Week_Of_Year)
Else
Week_Of_Year_New = Week_Of_Year
Year = DatePart("yyyy", PickedDate)
txt_week.Text = (Year) & (Week_Of_Year_New)
End If
 
Back
Top