Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Long Date into DateTime???

Status
Not open for further replies.

tqeonline

MIS
Oct 5, 2009
304
US
I have the following:

Code:
select cast('Friday, September 23, 2011 2:04:00 PM' as datetime)
and it returns an error but if i change it to:

Code:
select cast('September 23, 2011 2:04:00 PM' as datetime)

it works... is there a better way to remove the "Friday" or the 'day' from the datetime?

- Matt

"If I must boast, I will boast of the things that show my weakness"

- Windows 2003 Server, 98 SE, XP
- VB.NET, VSTS 2010, ASP.NET, EXCEL VBA, ACCESS, SQL 2008
 
This gives me the expected result, just thought there is an easier way:

Code:
declare @strDate as nvarchar(50)
set @strDate = 'Friday, September 23, 2011 2:04:00 PM'
select cast(right(@strDate,len(@strDate)-(CHARINDEX(',',@strDate)+1)) as datetime) as 'Date'

- Matt

"If I must boast, I will boast of the things that show my weakness"

- Windows 2003 Server, 98 SE, XP
- VB.NET, VSTS 2010, ASP.NET, EXCEL VBA, ACCESS, SQL 2008
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top