Highlighted

DaysDiff function with one date field?

Avatar

Avatar

robertw937098

Avatar

robertw937098

robertw937098

27-09-2018

Hi,

How can I calculate the days difference (using the daysdiff function) on one date field? Preferably for the most recent 3/4 dates in the field.

BACKGROUND: I need to know the days between each customers multiple journey dates for a campaign. Then work out the average of this number.

Many thanks,

Rob

Replies

Highlighted

Avatar

Avatar

Garima_Gakhar

Employee

Avatar

Garima_Gakhar

Employee

Garima_Gakhar
Employee

28-09-2018

Hi robertw937098

Date Difference could be calculated as: SELECT DATEDIFF(day, 'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:mm:ss');

PostgreSQL allows you a more accurate difference like (3 days, 10 hours) using the 'timestamp' option as below:

SELECT 'yyyy-mm-dd hh:mm:ss'::timestamp - 'yyyy-mm-dd hh:mm:ss'::timestamp;

'DATE_PART' prefixed to the above will again give difference in days.

SELECT DATE_PART ('day', 'yyyy-mm-dd hh:mm:ss'::timestamp - 'yyyy-mm-dd hh:mm:ss'::timestamp);

Hope that helps!

Highlighted

Avatar

Avatar

robertw937098

Avatar

robertw937098

robertw937098

01-10-2018

Hi Garima,

Thanks for your reply.

Though I still have the same issue. My question is, how is it possible to do a DaysDiff(@OUT_DATE_DEP) function on all the data in one date field per recipient?

For instance, something like... DaysDiff(row1.@OUT_DATE_DEP,row2.@OUT_DATE_DEP)

E.g. The below customer has many out date dep dates.

1583581_pastedImage_1.png

Many Thanks,

Rob

Highlighted

Avatar

Avatar

Debabrata_T

Avatar

Debabrata_T

Debabrata_T

24-10-2018

Hi Robert,

Difference can be found between two fields. But if you are going for difference between all the dates for one Recipient you won't get one output rather many rows. Can you please explain how you want your output to look like?

Regards,

Deb