Difference in milliseconds

Poel van der, RE (Ron) 451 Reputation points
2021-04-06T15:56:01.203+00:00

Hi

we have a SQL DB containing two fields, both defined as datetime2

fieldA 2020-10-20 07:25:58.4543440
fieldB 2020-10-20 07:25:58.4658980

We need to know the difference in milliseconds between fieldA and fieldB.

This doesn't work:
millisecond(fieldB , 'yyyy-MM-dd HH:mm:ss.SSSSSSS') - millisecond(fieldA, 'yyyy-MM-dd HH:mm:ss.SSSSSSS')

I get some strange error in the expression builder:

{"value":"11","type":"LosslessNumber","isLosslessNumber":true}

Anybody knows what I am doing wrong??
Tried other options, but don't get it working.

By the way, an additional requirement: If one of the fields contains a NULL value, the outcome must be 0.

regards
Ron

@HarithaMaddi-MSFT
@MartinJaffer-MSFT

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,627 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Saurabh Sharma 23,846 Reputation points Microsoft Employee Moderator
    2021-04-07T00:25:24.183+00:00

    Hi @Poel van der, RE (Ron) ,

    Thanks for using Microsoft Q&A !!
    Can you please pass only the column name to the function as per the documentation, as second parameter is a used for passing a timezone.
    millisecond(fieldB) - millisecond(fieldA)

    I have used it and it worked fine for me -
    Source Table
    85133-image.png

    **Used Derived Column expression for testing **
    85151-image.png

    Result
    85090-image.png

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    0 comments No comments

  2. Poel van der, RE (Ron) 451 Reputation points
    2021-04-07T08:55:17.013+00:00

    Hi @Saurabh Sharma

    It partially worked. The values 11 and 6 are correct, but why do I get all that surrounding text like ' {"value": ' etc. ?

    85149-knipsel2.jpg

    Regards
    Ron


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.