-1

According to this answer: https://stackoverflow.com/a/25863597/12304000

We can use something like this in mysql to calculate the time diff between two cols:

SELECT TIMESTAMPDIFF(<INTERVAL>,<timestampFrom>,<timestampTo>);

How can I achieve the same thing with pandasql? I tried these:

from pandasql import sqldf
output = sqldf("select DATEDIFF(minute,startDate,completedDate) from df")
output = sqldf("select TIMESTAMPDIFF(MINUTE,startDate,completedDate) from df")

but they throw an error that:

OperationalError: no such column: MINUTE

1 Answer 1

1

From the PandaSQL documentation:

pandasql uses SQLite syntax.

The link in your post is for MySQL. Here is a reference for SQLite https://www.sqlite.org/lang.html

The syntax would be like:

"select ROUND((JULIANDAY(startDate) - JULIANDAY(completedDate)) * 1440) from df"

Sign up to request clarification or add additional context in comments.

2 Comments

which unit will the difference be here? and how can I change the unit?
It calculates the difference in days, multiplying it gives you your unit. * 24 would be hours, * 24 * 60 would be minutes * 24 * 60 * 60 would be seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.