question

RatanDara-5010 avatar image
0 Votes"
RatanDara-5010 asked PRADEEPCHEEKATLA-MSFT commented

Date functions in spark sql

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
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @RatanDara-5010,

Just checking in to see if the below answer provided by @VaibhavChaudhari helped. If this answers your query, do click Accept Answer and Up-Vote for the same. And, if you have any further query do let us know.

0 Votes 0 ·

Hello @RatanDara-5010,

Following up to see if the below suggestion was helpful. And, if you have any further query do let us know.

0 Votes 0 ·

1 Answer

VaibhavChaudhari avatar image
0 Votes"
VaibhavChaudhari answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.