Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Databricks Certified Associate Developer for Apache Spark 3.5 Exam - Topic 4 Question 23 Discussion

Posted by Harrison on Oct 20, 2026 at 05:40 AM

21 of 55.

What is the behavior of the function date_sub(start, days) if a negative value is passed into the days parameter?

Suggested Answer: A

In Spark SQL, the function date_sub(startDate, days) returns the date that is days before startDate.

If the days parameter is negative, Spark interprets it as subtracting a negative number, which effectively adds days to the date.

Example:

from pyspark.sql.functions import date_sub, lit

df = spark.createDataFrame([( '2024-10-01', )], ['dt'])

df.select(date_sub('dt', -5).alias('new_date')).show()

Output:

+----------+

| new_date |

+----------+

|2024-10-06|

+----------+

Why the other options are incorrect:

B: No error occurs; negative values are supported.

C: The start date changes if days 0.

D: Subtracting days would move the date backward, not forward.


Spark SQL Functions --- date_sub(startDate, days) and date_add(startDate, days) behavior.

Databricks Exam Guide (June 2025): Section ''Using Spark SQL'' --- working with date and timestamp functions.

===========

Get Premium Databricks Certified Associate Developer for Apache Spark 3.5 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
0 comments · newest first

Currently there are no comments in this discussion, be the first to comment!

0/2000 characters

Save Cancel