Link to home
Start Free TrialLog in
Avatar of Canavar
Canavar

asked on

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
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

try style 103  that s d/m/y
not y.m.d which is 102
Avatar of Dexstar
Dexstar

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*
ASKER CERTIFIED SOLUTION
Avatar of Dexstar
Dexstar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Canavar

ASKER

i sorted it mate sorry. had a bit of blackout!
Avatar of Canavar

ASKER

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
>>Can an expert close this please?<<
No, but you can. See here:
What are my choices?
https://www.experts-exchange.com/help/closing.jsp#1

Anthony