As the title says, the row count differs when doing a select using DATE and DATETIME. Please advise.
I’m trying to select rows between 1st and 5th Jan, 2012. The date column datatype is bigint (UNIX timestamp).
select * from table_name
where sample_timestamp between unix_timestamp('2012-01-01')*1000 and unix_timestamp('2012-01-05')*1000
If I include the time in HH:MM:SS, the rows returned are correct i.e.
select * from table_name
where sample_timestamp between unix_timestamp('2012-01-01 00:00:00')*1000 and unix_timestamp('2012-01-05 23:59:59')*1000
Any input will be much appreciated. Thanks.
‘2012-01-05’ is actually ‘2012-01-05 00:00:00’ which is not what you’re writing in the second select.
I suspect what you mean to do is
which as a bonus handles leap seconds correctly too 🙂