-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
x89
  • 2,798
  • 5
  • 46
  • 110

1 Answers1

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"

Edward Radcliffe
  • 537
  • 2
  • 11
  • which unit will the difference be here? and how can I change the unit? – x89 Apr 08 '22 at 20:07
  • 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. – Edward Radcliffe Apr 08 '22 at 20:14