Solved

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

Posted on 2009-05-11
3
262 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now