SQLite Forum

SQL query help for between times and grouping times
Login
I think that is still wrong -- this works for the 12 AM and 12 PM:

```
select *,
       printf('%4d-%02d-%02d %02d:%s',
            substr(EventDate, length(EventDate)-3, 4) + 0,
            substr(EventDate, 1, instr(EventDate, '/') - 1) + 0,
            trim(substr(EventDate, instr(EventDate, '/') + 1, 2), '/') + 0,
            substr(EventTime, 1, instr(EventTime, ':') - 1) + iif(instr(EventTime, 'PM') > 1 and substr(EventDate,1,2) != '12', 12, iif(instr(EventTime, 'AM') > 1 and substr(EventTime, 1, 2) == '12', -12, 0)),
            substr(EventTime, instr(EventTime, ':') + 1, 6)) as timestamp
  from trafficdata;
```