Help Converting Date in MS Access Query or SQL Query

Hello Experts,

I have a date format like this one 20150522T015904 in data.  How can convert to fields to show the date part and the time part. I want to show as mm/dd/yyyy for the data part and minutes and seconds for the time part.

Thanks in advance for your assistance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:

try this

select SUBSTRING('20150522T015904',5,2) +'/'+ SUBSTRING('20150522T015904',7,2) + '/'+SUBSTRING('20150522T015904',1,4)

Open in new window

Vitor MontalvãoMSSQL Senior EngineerCommented:
Assuming that the source data is string and that target data are date and time data types respectively, you can use this (replace DateColName with the real source column name):
SELECT CAST(LEFT(DateColName,8) AS DATE), CAST(SUBSTRING(DateColName,10,2)+':'+ SUBSTRING(DateColName,12,2)+':'+ RIGHT(DateColName,2) AS TIME)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
It this is Access, use this expression in your query:

TrueDate: CDate(Format(Left([YourDateField], 8),"@@@@\/@@\/@@"))

where YourDateField is the name of the field holding 20150522T015904.

This will create a true date value. Apply any format to this, like "mm/dd/yyyy" or just "Short Date".

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.