Solved

convert MONDAY, SEPTEMBER 21, 1942 to Datetime

Posted on 2008-10-12
2
319 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
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

828 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