Solved

SQL: convert string value to a datetime value.

Posted on 2003-10-30
6
223 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
Comment Utility
try style 103  that s d/m/y
not y.m.d which is 102
0
 
LVL 19

Expert Comment

by:Dexstar
Comment Utility
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
Comment Utility
Doh!  So close!
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

Author Comment

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

Author Comment

by:Canavar
Comment Utility
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
Comment Utility
>>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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

744 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

9 Experts available now in Live!

Get 1:1 Help Now