Solved

convert MONDAY, SEPTEMBER 21, 1942 to Datetime

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Complex SQL 10 34
SQL Server memory Issue 7 74
SQL Date Retrival 7 30
Increasing Identity length in sql server 4 20
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now