Solved

convert MONDAY, SEPTEMBER 21, 1942 to Datetime

Posted on 2008-10-12
2
325 Views
Last Modified: 2013-11-30
I have a data file I am trying to convert into either a SQL Server or  Postgres database.  How can I convert the following date field value into a string compatible with either a Postgres or SQL Server date field?

MONDAY, SEPTEMBER 21, 1942

I will give points for either a way in Postgres or SQL Server.  Preferrably in T-SQL or pl/pg SQL
0
Comment
Question by:FreightTrain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
furrybootsistheanswer earned 500 total points
ID: 22699557
Is your date as string currently? If so, you can use charindex and substring to remove the leading 'DAYNAME, '  and then simply convert to datetime. In SQL server:

select convert(datetime,substring('MONDAY, SEPTEMBER 21, 1942',(charindex(',','MONDAY, SEPTEMBER 21, 1942') +2), (len('MONDAY, SEPTEMBER 21, 1942') -1)),101)

0
 

Author Closing Comment

by:FreightTrain
ID: 31505524
Yes, it is a string!  AWESOME!  Thank You!!!  
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

691 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