I am creating a table which will have 2 columns:
- Day_time (time from
1978-01-01 00:00:00
Sunday, till1978-01-07 23:59:00.0
Saturday, Granularity: Minute) - Time_id (a unique id for each minute), to be populated
I have column one populated. I want to populate column two.
How I am doing it right now:
EXTRACT(dayofweek FROM day_time) * 10000 + DATEDIFF('minutes', TRUNC(day_time), day_time)
I basically want a function where I pass any date and it tells me where I am in a week. So, I need a function, just like the function above. Just more optimized, where I give a date and get a unique ID. The unique ID should repeat weekly.
Example: ID for
Jan 1, 2015 00:00:00
will be same asJan 8, 2015 00:00:00
.
Why 1978-01-01? cuz it starts from a Sunday.
Why 10,000? cuz the number of minutes in a day are in four digits.