Ana-Maria Ludu
Ana-Maria Ludu

Reputation: 3

Azure Data Factory - calculate the number of days between two dates

I have to calculate the number of days between two dates and I search and I don't find any similar function available in ADF.

enter image description here

what I've noticed so far is that if I want to get the number of days between 2 columns, it means that the columns must be date columns, but I have timestamp columns (date + time)

how can I transform these columns into Date columns? or do you have other idea?

Upvotes: 0

Views: 7933

Answers (2)

Ana-Maria Ludu
Ana-Maria Ludu

Reputation: 1

This is the expression that I used for Data Flow.

toDate(toString({max_po create date},'yyyy-MM-dd')) - toDate(toString(max_datetimetoday,'yyyy-MM-dd'))

max_po, create date and max_datetimetoday are TimeStamp(date + time) columns.

The result is in days.

Upvotes: 0

KarthikBhyresh-MT
KarthikBhyresh-MT

Reputation: 5034

Using the fact that 86,400 is the number of seconds in a day

Now, using the function ticks, it returns the ticks property value for a specified timestamp. A tick is a 100-nanosecond interval.

@string(div(sub(ticks(last_date),ticks(first_date)),864000000000))

Can re-format any type timestamp using function formatDateTime()

@formatDateTime(your_time_stamp,'yyyy-MM-dd HH:mm:ss')

Example:

enter image description here enter image description here

@string(div(sub(ticks('2022-02-23 15:58:16'),ticks('2022-01-31 15:58:16')),864000000000))

enter image description here

Upvotes: 4

Related Questions