Difference between varchar dates


Difference between varchar dates

Hi Guys,


I want to take difference of 2 date fields but both are varchar field

SyntaxEditor Code Snippet

start_time- 2018-03-02 06:31:22

end_time -  2018-03-02 06:33:32.478000  

I want the result in integer as 2 in min always  and it should be an integer always

Result :- 2


It would be very great if anyone can help to achieve my case.



Teradata Employee

Re: Difference between varchar dates

If the difference can never be more than 9999 seconds, you could do something relatively straightforward:

cast((cast(end_time as timestamp) - cast(start_time as timestamp) minutes(4)) as integer).


Also see this post for a more general approach which you can use or adapt.