SQLite Forum

Calculating duration in ISO8601 timestamp
Login
Hi,

Assume this is the start time of an event:
`2021-07-19 08:43:46:956`

and this is the end time:
`2021-07-20 10:26:41:357`

The times are using 24 hour timestamps.


Can the duration be calculated between these?

**What I've tried:**

```
select
	min(datetime) as Start,
	max(datetime) as End,
	datetime(max(datetime)) - datetime(min(datetime)) as duration	
from
	table1
```

...


```
select
	strftime(max(datetime)) as max,
	strftime(min(datetime)) as max,
strftime(max('%Y-%m-%d %H:%M:%S',datetime)) - strftime(min('%Y-%m-%d %H:%M:%S',datetime)) as Duration

from table1
```

...


```
select
	start,
	end,
	duration
from (
	select
		min(datetime) as start,
		max(datetime) as end,
		julianday('datetime') - julianday('now') as duration
from table1
);
```

Results are always blank or 0. Clearly it can't be! The columns are of 'text'. Do I need to cast it to something else?

Thanks!