SQL: convert string value to a datetime value.

Posted on 2003-10-30
Last Modified: 2012-05-04

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.

Question by:Canavar
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 50

Expert Comment

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

Expert Comment

ID: 9651688

> 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 ''.

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

Hope that helps,
LVL 19

Accepted Solution

Dexstar earned 20 total points
ID: 9651695
Doh!  So close!
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.


Author Comment

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

Author Comment

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?

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?


Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query 9 28
Display Day name if condition is true in crystal report (VB.Net) 2 36
SQL Job Failed 6 31
Error converting data type varchar to numeric. 4 7
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…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

739 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