Solved

SQL: convert string value to a datetime value.

Posted on 2003-10-30
6
227 Views
Last Modified: 2012-05-04
Hi,

I need a SQL statement to convert a string to a legitimate datetime value.
String i'm entering is '30/10/2003' and i'm using the following SQL code to convert it;
Convert(datetime, @StartDate, 102) where start date is '30/10/2003'.
when i try this in query analyzer i get the error message below.
Error converting data type varchar to datetime.

help!
Ozi
0
Comment
Question by:Canavar
6 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 9651663
try style 103  that s d/m/y
not y.m.d which is 102
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9651688
Canavar:

> String i'm entering is '30/10/2003' and i'm using the following SQL code to convert it;
> Convert(datetime, @StartDate, 102) where start date is '30/10/2003'.

102 is for when you have 'yyyy.mm.dd'.

You have 'dd/mm/yyyy', which is 103.  So try this instead:
     Convert(datetime, @StartDate, 103)

Hope that helps,
Dex*
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 20 total points
ID: 9651695
Doh!  So close!
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:Canavar
ID: 9651698
i sorted it mate sorry. had a bit of blackout!
0
 

Author Comment

by:Canavar
ID: 9651730
Thanks guys anyway. i just had to get away from my desk and come back with a clear mind!

Can an expert close this please?

thanks,
Canavar
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9652150
>>Can an expert close this please?<<
No, but you can. See here:
What are my choices?
http://www.experts-exchange.com/help/closing.jsp#1

Anthony
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sql server insert 13 31
Sql server function help 15 31
Query Help - MSSQL - Averages 5 27
Need help with a Stored Proc on Sql Server 2012 4 11
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

810 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