Date functions in spark sql

Rathnakar Dara 1 Reputation point
2021-07-09T11:39:19.34+00:00

Hi,
I am using sql query in synapse notebook and unable to use getdate() function in sql query. Please advice.

this query not working
df= spark.sql("""SELECT period_id FROM dim_period_dates
WHERE
GetDate() -1 BETWEEN period_start AND period_end """).

this query is working

df= spark.sql("""SELECT period_id FROM dim_period_dates
WHERE
date_sub(Current_Date(),1) BETWEEN period_start AND period_end
""")

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,916 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vaibhav Chaudhari 38,736 Reputation points
    2021-07-09T11:45:55.783+00:00

    In Spark SQL, you can get the current date details only by using current_date() and current_timestamp() so getdate() which is SQL Server function won't work here


    Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.