You can get the hour portion of the time from a date data type using the hour method. However, this returns 5 for 5:00 AM, and 5 for 5:00 PM.
What technique do you use to get this in 24-hour format? I would like 5 for 5:00 AM, and 17 for 5:00 PM.
Printable View
You can get the hour portion of the time from a date data type using the hour method. However, this returns 5 for 5:00 AM, and 5 for 5:00 PM.
What technique do you use to get this in 24-hour format? I would like 5 for 5:00 AM, and 17 for 5:00 PM.
You sure about that? Maybe it's windows setting or something, but this worked fine for me, that is, it returns 17, not 5
VB Code:
Dim myDate As Date = New Date(2004, 9, 28, 17, 42, 42) MessageBox.Show(myDate.Hour)
I can see why that would work, I kind of thought that if I put in hours in 24 hour format, it would recognize it. However, I want to get the hour out of a file creation time, which is in 12 hour format. It seems like there ought to be a way to take a time in 12 hour format and return it in 24 hour format, but I haven't seen any obvious solution.
ok, but you said you were using the "date data type". What's your code look like?
I don't have it around here, but it is something like this:
VB Code:
dim dt as date dt=fil.datecreated 'Actually, I just made up that last line, but you get the idea. if dt.hour <5 then 'Something end if
That is pretty contrived, but it covers the idea. dt.Hour will return 3 for either 3:00AM or 3:00PM. This would mean that 3:00 PM would be true in the if statement, when what I want is for it to be false.
Real code would help, but this works fine, that is, the last modified time is 3:49 PM and you see "15" in the message box
VB Code:
Dim fi As FileInfo = New FileInfo("c:\temp\sleuth-small.jpg") MessageBox.Show(fi.LastWriteTime.Hour)
I'll have to check this, but it sure looks like what I was doing. I didn't get 15, though, I got 3.
I'll have another look this evening. Maybe there is some environment setting in windows.
The documentation states that the Hour property is a number between 0 and 23.
If (PM) then Hours += 12 :D
It's that If (PM) part that is the problem. Is there something that returns that?
I'll have to look again at the hours, I don't think that is what I got, but it was late. I suppose I might have seen the wrong thing.
Oops, I guess it was 24 hour time. My problem was elsewhere. I guess I was too tired to be writing.