|
-
Sep 28th, 2004, 09:27 AM
#1
Problem with hours in dates(Resolved)
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.
Last edited by Shaggy Hiker; Sep 29th, 2004 at 10:16 AM.
-
Sep 28th, 2004, 09:43 AM
#2
Frenzied Member
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)
-
Sep 28th, 2004, 09:50 AM
#3
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.
-
Sep 28th, 2004, 09:52 AM
#4
Frenzied Member
ok, but you said you were using the "date data type". What's your code look like?
-
Sep 28th, 2004, 10:20 AM
#5
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.
My usual boring signature: Nothing
 
-
Sep 28th, 2004, 10:41 AM
#6
Frenzied Member
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)
-
Sep 28th, 2004, 11:52 AM
#7
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.
My usual boring signature: Nothing
 
-
Sep 28th, 2004, 11:54 AM
#8
Frenzied Member
The documentation states that the Hour property is a number between 0 and 23.
-
Sep 28th, 2004, 12:23 PM
#9
If (PM) then Hours += 12
-
Sep 28th, 2004, 01:21 PM
#10
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.
My usual boring signature: Nothing
 
-
Sep 29th, 2004, 10:16 AM
#11
Oops, I guess it was 24 hour time. My problem was elsewhere. I guess I was too tired to be writing.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|