Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when iam trying to execute this query it return sql server error Conversion failed when converting date and/or time from character string


SQL
select DATEDIFF(HOUR,CONVERT(varchar(19),inputDate),CONVERT(varchar(19),startingWork)) from TICKET_LOG

17-10-2015 11:30:51 and 12/4/2014 8:38:00 A string


what is the error ? anyone can help me to solve the issue ??
Posted
Updated 17-Oct-15 3:09am
v2
Comments
Maciej Los 17-Oct-15 9:10am
   
What is inputDate and startingWork?

You can only use certain operations on certain data types. You cannot datediff varchars.

If your input type is a date type then don't convert it

if it's not a date type, and you're extracting a date or datetime part then you need to convert that into a date type after you have converted it to varchar(19)
   
set the format

CONVERT(varchar(19),inputDate,106)
there is some format to convert string to date

find below link for sql format

[http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900