Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

DaysDiff function with one date field?

Level 2
Level 2


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,


3 Replies

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!

Level 2
Level 2

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.


Many Thanks,


Level 6
Level 6

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?