• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

SQL: convert string value to a datetime value.

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
Canavar
Asked:
Canavar
1 Solution
 
LowfatspreadCommented:
try style 103  that s d/m/y
not y.m.d which is 102
0
 
DexstarCommented:
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
 
DexstarCommented:
Doh!  So close!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
CanavarAuthor Commented:
i sorted it mate sorry. had a bit of blackout!
0
 
CanavarAuthor Commented:
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
 
Anthony PerkinsCommented:
>>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now