Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL: convert string value to a datetime value.

Posted on 2003-10-30
6
Medium Priority
?
243 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
[X]
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
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 60 total points
ID: 9651695
Doh!  So close!
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

670 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