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,020 points
2,443 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,680 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,020 points
6,123 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,020 points
499 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,020 points
884 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,902 views
0 votes
0 answers

Selecting COUNT(*) with DISTINCT

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

Feb 14, 2022 in Database by Neha
• 9,020 points
457 views
0 votes
1 answer
0 votes
1 answer

How to extract only the year from the date in sql server 2008?

To obtain the year from the given ...READ MORE

answered Sep 15, 2022 in Database by narikkadan
• 63,680 points
868 views
0 votes
1 answer

How to execute function in SQL Server 2008

The function appears not to be being ...READ MORE

answered Sep 11, 2022 in Database by narikkadan
• 63,680 points
932 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP