Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do you get the data in VB6

Posted on 2005-03-06
4
Medium Priority
?
175 Views
Last Modified: 2008-02-01
What's the code that will give you today's date in Visual Basic 6?
Can you get the date separate from the time?
Thank you!
Angie
0
Comment
Question by:Angie532
  • 2
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 200 total points
ID: 13471477
The Date type stores date and time.  Use Now() to get current date/time, and Format() to display it.

Dim dt As Date

'get the date/time now
dt = Now

'display
MsgBox _
"Today is " & Format(dt, "mm/dd/yyyy") & vbCrLf & _
"Time is  " & Format(dt, "hh:nn:ss AMPM")
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13471499
You could also get date and time separately using Date() and Time() functions:

Dim dt As Date
Dim tm As Date

'get the date/time now
dt = Date
tm = Time

'display
MsgBox _
"Today is " & Format(dt, "mm/dd/yyyy") & vbCrLf & _
"Time is  " & Format(tm, "hh:nn:ss AMPM")
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13474520
You can try and do it like so :

Dim strDate As String
strDate = Day(Now) & "/" & Month(Now) & "/" & Year(Now)
MsgBox strDate
MsgBox Format$(Now, "Medium Time")
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13474526
This site shows you what you can use within the format function, if you use short date within the format function , it will make it display the time in a 24 hour format :)

http://juicystudio.com/tutorial/vb/vbdates.asp
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question