Create a date from data import

L

Lee

I linked to a SQL file and did a query as the file is too large to import
using Access 2007. The query pulled in a date field with the date formated
as 20090515. I use Excel and can create a date using
date(left(),mid(),right()) but haven't a clue in Access. Any help is greatly
appreciated.
Thanks,
Lee
 
K

Ken Snell MVP

DateValueResult: DateSerial(CLng(Left(NameOfYYYYMMDDField, 4)),
CLng(Mid(NameOfYYYYMMDDField, 5, 2)), CLng(Right(NameOfYYYYMMDDField, 2)))
 
J

John W. Vinson

I linked to a SQL file and did a query as the file is too large to import
using Access 2007. The query pulled in a date field with the date formated
as 20090515. I use Excel and can create a date using
date(left(),mid(),right()) but haven't a clue in Access. Any help is greatly
appreciated.
Thanks,
Lee

Ken's DateSerial, or more compactly

CDate(Format([datefield], "@@@@\-@@\-@@"))
 
J

John Spencer

I always test the value first to handle errors that are caused by nulls
or invalid dates.

IIF(IsDate(Format([datefield],"@@@@\-@@\-@@")),CDate(Format([datefield],"@@@@\-@@\-@@")),null)

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

I linked to a SQL file and did a query as the file is too large to import
using Access 2007. The query pulled in a date field with the date formated
as 20090515. I use Excel and can create a date using
date(left(),mid(),right()) but haven't a clue in Access. Any help is greatly
appreciated.
Thanks,
Lee

Ken's DateSerial, or more compactly

CDate(Format([datefield], "@@@@\-@@\-@@"))
 
L

Lee

Thanks for the help, this is much different than excel.
Lee
John Spencer said:
I always test the value first to handle errors that are caused by nulls or
invalid dates.

IIF(IsDate(Format([datefield],"@@@@\-@@\-@@")),CDate(Format([datefield],"@@@@\-@@\-@@")),null)

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

I linked to a SQL file and did a query as the file is too large to
import using Access 2007. The query pulled in a date field with the date
formated as 20090515. I use Excel and can create a date using
date(left(),mid(),right()) but haven't a clue in Access. Any help is
greatly appreciated.
Thanks,
Lee

Ken's DateSerial, or more compactly

CDate(Format([datefield], "@@@@\-@@\-@@"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top