-
Apr 6th, 2012, 07:38 AM
#1
Thread Starter
PowerPoster
[RESOLVED] How can I get the local time on the computer?
Hi there, I am finishing up a math prog and I am trying to get it to save the students marks to a textfile, and I include a bit of information about the test in the textfile file name. I got the calendar date, but would like to include the hour and min, and possibly the AM Or PM.
Would anyone know of a way to grab the time and put it into a label caption? Thank you!!
-
Apr 6th, 2012, 07:49 AM
#2
Re: How can I get the local time on the computer?
You can get the date using the Date function, and the time using the Time function, or both together using Now.
To store any of those into a String in a particular format, use the Format function.
-
Apr 6th, 2012, 08:02 AM
#3
Thread Starter
PowerPoster
Re: How can I get the local time on the computer?
Ok LOl I didn't know it was that simple.
So my code looks like this
TimeLBL.caption = Format(Time, (Now))
So I get the date, 06/04/2012, and the time 10:00:02AM.
Now I like that, I like that a lot, but what would I have to do to just get the time?
Also, are you allowed colons in filenames? Thanks!
-
Apr 6th, 2012, 08:37 AM
#4
Thread Starter
PowerPoster
Re: How can I get the local time on the computer?
I just checked and it won't let me use colons in a filename. Would there be a way to get the time, but have it formatted to give me time like this..
10h 37minAM?
-
Apr 6th, 2012, 09:15 AM
#5
Re: How can I get the local time on the computer?
Something like this: hour(time) & "h " & minute(time) & "min" & format(time,"AM/PM")
But a more reasonable solution for filenames may be to use hour/time with leading zeroes:
format(time,"hhnn")
-
Apr 6th, 2012, 10:02 AM
#6
Junior Member
Re: How can I get the local time on the computer?
Easiest way, no APIs or anything.
Code:
Debug.Print TimeValue(Now) 'Fectches the Current Computer Time
Debug.Print DataValue(Now) 'Fetches the current computer date
Theres many ways to do this, such as the format function, but i find this the easiest and as you can see takes up no room.
Hope this was helpful,
Cypher
-
Apr 6th, 2012, 10:08 AM
#7
Thread Starter
PowerPoster
Re: How can I get the local time on the computer?
-
Apr 6th, 2012, 10:09 AM
#8
Junior Member
Re: [RESOLVED] How can I get the local time on the computer?
No problem, hope you can incorperate this into your project.
-
Apr 6th, 2012, 11:39 AM
#9
Re: [RESOLVED] How can I get the local time on the computer?
I don't think that's particularly clever. For example:
Code:
Debug.Print DateValue(Now)
compiles as
Code:
Debug.Print CStr(CDate(Fix(CDate(CStr(Now)))))
Hardly "takes no room."
-
Apr 6th, 2012, 02:54 PM
#10
Junior Member
Re: [RESOLVED] How can I get the local time on the computer?
not clever? it doesn't take no room at all, and get the current time or date of the computer.
-
Apr 6th, 2012, 03:29 PM
#11
Re: [RESOLVED] How can I get the local time on the computer?
Just use the Time() function then as suggested in post #2. It is even more brief and it doesn't go through as many gyrations.
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
|