Solved

How to Convert MON DD HH:MM:SS YYYY Format in VB?

Posted on 2009-05-11
3
269 Views
Last Modified: 2012-05-06
I have a date/time value I'm reading from a database that returns the date/time in this format:
May 01 16:17:32 2009    ... I would like to convert this to a better format, such as this:
05/01 16:17:32

I don't see an easy way to do that in VB ... can someone help?  Thanks.
0
Comment
Question by:UPRRDevelopers
3 Comments
 
LVL 7

Accepted Solution

by:
FER_G earned 500 total points
ID: 24354265
UPRRDevelopers; I think that could be many ways to get that you want.
I only recommend you this one.

'Apply a Split function to the date
strDate="May 01 16:17:32 2009"
aDate=split(strDate," ")

doing this, you'll get all the data in a separate element of the array...
i.e.:
?aDate(0) --> month
?aDate(1) --> day
?aDate(2) --> hour
?aDate(3) --> year

so whit this, you can format and generate the date in the format that you need


FerG
Saludos.
--
Ing. Fernando D. Giletta
San Francisco. Córdoba. Argentina.
0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 24354721
If the date is indeed stored as a date in the database, you can do
dim MyDate as string
MyDate = Format(rs.fields("DBDateField"), "mm/dd Hh:Nn:Ss")
0
 

Author Closing Comment

by:UPRRDevelopers
ID: 31580133
Perfect... thanks for the quick answer!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

803 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