Ordering withing current date

Hi to all.

I have a problem with sorting data withing current_date.

For example i have a table that have field wdate as timestamp. I need to extract all record for today but from 06 in the morning to 24.

In the beginning i was working order by wdate ASC but i need this way of ordering, is it possible?

Thank you!

that’s quite interesting :slight_smile:

I found better solution, and if someone will have something like this in the future here it is :

wdate BETWEEN TO_CHAR(current_date + interval ‘06:00’, ‘YYYY-MM-DD HH24:MI:SS’) AND TO_CHAR(current_date + interval ‘1 day 06:00’, ‘YYYY-MM-DD HH24:MI:SS’)

field type TIMESTAMP

timestamp as in TIMESTAMP (essentially a date and time), or timestamp as in unix timestamp (an INTEGER like 1279734431)?

CASE
WHEN TO_CHAR(wdate, ‘HH24’) BETWEEN ‘24’ AND ‘06’ THEN ‘b’
WHEN TO_CHAR(wdate, ‘HH24’) BETWEEN ‘06’ AND ‘24’ THEN ‘a’
ELSE ‘evening’ END as wha

Then i order by wha asc and wdate asc - thats it :slight_smile: