Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date to string in VBA

Status
Not open for further replies.

aabob

MIS
Sep 21, 2001
3
US
Pardon the newbie question, but how do I convert a date to a string in my VBA code for the purpose of evaluation?

Foxpro uses 'DTC' but I can find the VBA way.

Thanks.
 
Hi!

Try this:

Format(DateField, "mm/dd/yyyy")

The string tells Access how you want it formatted.

hth
Jeff Bridgham
 
There is also the CSTR function, which I believe will turn a date into a string... Terry M. Hoey
 
No, "Cstr" converts a number to a string.
 
A date is a string; you don't need to convert it. You can perform string functions such as Left$, Mid$, etc. on the date with "converting" it. Formatting only changes the way the data is displayed, not how it's stored.

Uncle Jack
 

FYI

Dates are stored as numeric values in Access. You can use string functions on dates because Access implicitly converts dates to strings when needed. Dates are converted to strings based on the computer's settings. One PC may return today's date as 9/22/01, another as 09/22/2001 and yet another as 2001-09-22 and so forth.

CStr will convert a date to a string but does so according to the PC settings. Format(DateCol) without any formatting parameters also returns a string that is formatted according to the PC's settings.

In order to properly perform string manipulations on dates, the programmer should explicitly format dates. Of course, if all you want is a string and will not be manipulating the string with mid, left, right, etc. then any of these conversion methods will work. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top