Computing.Net > Forums > Programming > Date and time in VB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Date and time in VB

Reply to Message Icon

Name: raylu
Date: January 1, 2004 at 11:15:46 Pacific
OS: XP Pro
CPU/Ram: 1.1G
Comment:

I feel really stupid for asking this but how do you get the current date and time in VB?



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: January 1, 2004 at 13:57:49 Pacific
Reply:

Use the system variable Date and Time.

Stuart



0

Response Number 2
Name: raylu
Date: January 1, 2004 at 14:51:34 Pacific
Reply:

Oh...
;-) Thanks.


0

Response Number 3
Name: Burbble
Date: January 2, 2004 at 21:37:23 Pacific
Reply:

You can also use Date$ (which returns the date using different separators - colons instead of backslashes, I think) and Time$ (which returns military time).

-Burbble


0

Response Number 4
Name: StuartS
Date: January 2, 2004 at 23:07:31 Pacific
Reply:

Well actually Date and Date$ and Time and Time$ return exactly the same thing. The format is determined by the setting in Control Panel > Regional Settings.

If you format the time with HH you get a 24 hour clock. hh gives you a twelve hour clock. tt on the end of the format string gives you AM or PM as appropriate.

Now or Now$ in VB will give you the date and time combined.

Stuart


0

Response Number 5
Name: raylu
Date: January 3, 2004 at 10:12:28 Pacific
Reply:

Thank you all for replying. I need it to find how long a program takes to execute, so I took the Left 2 characters of the Right 5 characters of the Time for the start and end time and subtracted it (Using a time won't work, I already tried). There has to be an easier way.
By the way, thanks for the Now. I've been using Date & " " & Time.


0

Related Posts

See More



Response Number 6
Name: StuartS
Date: January 3, 2004 at 13:40:00 Pacific
Reply:

Thats not a very good way of timing events within a programme. Although the system clock can be very accurate, its resolution os not so good. At best 1/18th of a second.

A better method is to use the GetTickCount API. Thus returns the number of milliseconds since the computer was started.

Call the function at the start of the event and save the result. Call it again at then end of the event. Subtract one from the other and a bit of devision and you have an answer accurate to 15Ms

Public Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long

Stuart


0

Response Number 7
Name: wsd
Date: January 9, 2004 at 00:07:00 Pacific
Reply:

EXAMPLE:
Dim Mydate As String
Mydate = Format(Date, "dddd, mmm d yyyy, hh:mm:ss AMPM")


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Date and time in VB

batch file name date and time www.computing.net/answers/programming/batch-file-name-date-and-time/15060.html

Batch File - date and time on files www.computing.net/answers/programming/batch-file-date-and-time-on-files/9137.html

list file's current date and time. www.computing.net/answers/programming/list-files-current-date-and-time/11922.html