Forum Discussion
How calculating the difference between two datetimes in minutes in pyspark SQL
- 1 year ago
Hi, thanks for your reply.
I've solved with:
sql_sample_table = """ SELECT * FROM mytable WHERE cast(((unix_timestamp()-unix_timestamp(mytimestamp)) / 60) as int) > 30 """ spark.sql(sql_sample_table).show()unix_timestamp() returns the current timestamp in seconds.
The unix_timestamp statement in Spark SQL returns the number of seconds that have passed since January 1, 1970 (epoch time) until the specified date and time.
Thanks
Chat GPT suggests the following, does it work in your case?
sql_sample_table = """
SELECT *
FROM mytable
WHERE (unix_timestamp(current_timestamp()) - unix_timestamp(mytimestamp)) > 30 * 60
"""
spark.sql(sql_sample_table).show()
- pmscorca1 year agoKudo Kingpin
Hi, thanks for your reply.
I've solved with:
sql_sample_table = """ SELECT * FROM mytable WHERE cast(((unix_timestamp()-unix_timestamp(mytimestamp)) / 60) as int) > 30 """ spark.sql(sql_sample_table).show()unix_timestamp() returns the current timestamp in seconds.
The unix_timestamp statement in Spark SQL returns the number of seconds that have passed since January 1, 1970 (epoch time) until the specified date and time.
Thanks
- Anonymous1 year agoNot applicable
HI pmscorca,
I'm glad to hear you get the resolution and share it here, they will help others who has the similar requirement.
Regards,
Xiaoxin Sheng