inapathtolearn
inapathtolearn

Reputation: 75

Error while finding the time difference in SQL Sybase using DATEDIFF function

enter image description here

I have the following query to find the difference between two dates in minutes.

SELECT DATEDIFF(MINUTE,'28.11.2019 09:23:41:202',GETDATE()) AS time_difference

But, I am getting the error

Converting '28.11.2019 09:23:41:202 'to timestamp is not possible SQLCODE = -157, ODBC 3 State = "07006"

The value '28.11.2019 09:23:41:202' is obtained by using GETDATE() function in a previous query. What is wrong here? any help?

UPDATE:

The query works if the value '28.11.2019 09:23:41:202' is changed to "2019.11.28" format. As mentioned above,

The value "'28.11.2019 09:23:41:202'" is obtained from using the same function GETDATE() in a previous query.

Upvotes: 0

Views: 595

Answers (2)

Tim Wooldridge
Tim Wooldridge

Reputation: 197

You need to utilise a standard date-time format, for it to work. For example, see following query:

select DateDiff(minute, '2019-11-28 08:12:34', GetDate()) as time_difference

Upvotes: 2

fargbling
fargbling

Reputation: 16

Example from Official documentation:

SELECT DATEDIFF(minute,      '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000');

Upvotes: 0

Related Questions