SQL Server string to date conversion

0 votes

I want to convert a string like this:

'10/15/2008 10:06:32 PM'

Into the equivalent DATETIME value in Sql Server.

In Oracle, I would say this:

TO_DATE('10/15/2008 10:06:32 PM','MM/DD/YYYY HH:MI:SS AM')

This question implies that I must parse the string into one of the standard formats, and then convert using one of those codes. That seems ludicrous for such a mundane operation. Is there an easier way?

Sep 14, 2022 in Database by Kithuzzz
• 38,010 points
2,198 views

1 answer to this question.

0 votes

Try this

Cast('7/7/2011' as datetime)

And

Convert(DATETIME, '7/7/2011', 101)

See CAST and CONVERT (Transact-SQL) for more details.

answered Sep 16, 2022 by narikkadan
• 63,720 points

Related Questions In Database

0 votes
0 answers

Convert date from dd-mm-yyyy to yyyy-mm-dd in SQL Server

Given date: DECLARE @Date1 VARCHAR(50) = '30-01-2015' I want ...READ MORE

Aug 18, 2022 in Database by Kithuzzz
• 38,010 points
5,939 views
0 votes
0 answers
0 votes
0 answers

How to return only the Date from a SQL Server DateTime datatype

SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part ...READ MORE

Sep 6, 2022 in Database by Kithuzzz
• 38,010 points
433 views
0 votes
1 answer
0 votes
0 answers

How to get Time from DateTime format in SQL?

I want to use a SQL query ...READ MORE

Aug 15, 2022 in Database by Kithuzzz
• 38,010 points
727 views
0 votes
1 answer

SQL query to select dates between two dates

you should put those two dates between ...READ MORE

answered Nov 7, 2022 in Others by gaurav
• 23,260 points
2,730 views
0 votes
0 answers

Selecting COUNT(*) with DISTINCT

In SQL Server 2005, I have a ...READ MORE

Feb 14, 2022 in