Ask Your Question
3

How to find the difference in number of days between two dates using Spark SQL?

asked 2023-06-24 19:03:02 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-24 19:04:02 +0000

qstack gravatar image

You can use the DATEDIFF function in Spark SQL to find the difference in number of days between two dates. Here is an example:

SELECT DATEDIFF('2021-10-15', '2021-10-10') AS day_diff;

This will return the difference in number of days between October 10, 2021 and October 15, 2021, which is 5.

You can replace the date strings in the example with column names from a table to calculate the difference between dates in that table.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-24 19:03:02 +0000

Seen: 11 times

Last updated: Jun 24 '23