Click to See Complete Forum and Search --> : [Urgent] Timing Allocation Problem


evios
June 22nd, 2008, 11:08 PM
Lets say i do this to count the number of that particular hour:
If vDateTime.Hour > 0 And vDateTime.Hour < 24 Then
Dim hour As Integer = vDateTime.Hour
If hour = 0 Then
hour = 24
End If
count(hour, 0) = count(hour, 0) + 1
Refer to the data below:
1.2008/06/24 02:00
2.2008/06/24 12:00
3.2008/06/24 06:00
4.2008/06/24 17:00
5.2008/06/25 06:00
The first will be allocated to hour=02 and the second one will go to hour=12.
However i face this problem: How if 3 and 5 having the same hour but different date? I need to get the date as well. Can i solve this problem using almost the same coding format above? I need to keep count(hour, 0) = count(hour, 0) + 1 this way. Thanks a lot.

dglienna
June 22nd, 2008, 11:17 PM
You should always parse the date, rather than the hour, but you can also use DAY()

http://msconline.maconstate.edu/tutorials/VBNET/VBNET01/vbnet01-07.aspx

evios
June 23rd, 2008, 10:01 PM
Now i already simplify my coding to the format below:
I need to allocate the 24-hour time selected by the user to an array of size 24, for example, If the user choose 2day 8AM until tomorrow 7AM, Then my idea is:
hourarray(0)=8AM
hourarray(1)=9AM.....
..hourarray(23)=7AM...
How can i loop it? Thanks

dglienna
June 24th, 2008, 01:19 AM
your fields ahould be date/time. you can use a function to change it to hour minute or second

GremlinSA
June 24th, 2008, 06:34 AM
Okay ..

Look up DateDiff function.. and set up your code to do something alond the lines of ...

1) Get start date and time..
2) read in DATA ..(first/Next record)
3) Compare data(2) to start date (1) and skip all data before start date (go back to 2)
4) Get the Datediff of data(2) date and start date(1)
5) if Datediff day = 1 (more than 24 hours) go back to 2..
6) do your count...

Hope this Helps...

Gremmy...
6)

TheCPUWizard
June 24th, 2008, 08:17 AM
Why VB6 style solutions in the VB.NET forum...

Simply use DateTime and TimeSpan...problems all solved with no explicit parsing or even calculating....