Share via

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.


1 answer

Sort by: Most helpful
  1. Vaibhav Chaudhari 39,011 Reputation points Volunteer Moderator
    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

    Was this answer helpful?

    0 comments No comments

Your answer

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