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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with date conversion

Status
Not open for further replies.

eerich

IS-IT--Management
Joined
Nov 2, 2003
Messages
124
Location
US
Hello,

I've search the threads but could not find a solution to a date conversion issue I'm having. I'm trying to convert a string value to a date. The string is setup as:

fieldnme
2007-09-24 00:00:00.000

My sql is:

Select fieldnme, cdate(format(fieldnme, 'yyyy-mm-dd') as PostedDate
From Table;

I receive an error (#error) in the PostedDate field. I've tried adding double quotes around the format as well but it still produces the same error.

Any help would be appreciated.
 
Try

Code:
Select fieldnme, format(cdate(fieldnme), 'yyyy-mm-dd') as PostedDate
From Table;
 
Hi Captain D - thanks for the reply.

It still didn't work. Here's my query:

select format(cdate(posteddate), 'yyyy-mm-dd') as EntryDate
from Table1;

I receive a #error.

As noted in my first post, the string stored in each record is in the format:

PostedDate
2007-09-24 00:00:00.000
2008-02-13 00:00:00.000
 
Try
Code:
Select fieldnme, cdate(Left(fieldnme,10)) as PostedDate
From Table;


Duane MS Access MVP
 
Duane,

That worked!

Thanks
 

I ran these and no error, do all your fields have dates?

A field with a NULL value would throw an error.

Code:
SELECT Format(CDate(tDateTest.sDate),"MM-DD-YYYY") AS MyDate
FROM tDateTest;

AND

SELECT Format(CDate(tDateTest.sDate),"YY-MM-DD") AS MyDate
FROM tDateTest;
 
I ran these and no error
Really ?
CDate("2007-09-24 00:00:00[!].000[/!]") should raise error 13 ...
 
I got the same error a PH. In addition, the original question asked "I'm trying to convert a string value to a [red]date[/red]".

Using the Format() function on a field converts the value to a variant string rather than a date data type.

Duane MS Access MVP
 
I only entered my dates like this "2007-09-24 00:00:00", NO ".000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top