Skip to content
Advertisement

setting time range in SQL Developer

I am working on a dataset that contains car accidents and their time of occurrence. (the data set exists in SQL Server under the name accident).

I have a column that is in date format. I would like to extract the time from the column. Then add a new column called lightining_period label the time as daytime or nighttime. My problem is with setting a range for the times, as I get the wrong label each time I run the code.

Different lighting periods (daytime: 6AM – 5:59PM and nighttime 6PM – 5:59AM).

[1]First I wrote this code to extract the time from accident_date_time and store it in a new column time.

[2]Then, I altered the table to add the column lightining_label where I want to store the labels daytime/nighttime.

[3]Finally, I used Update statement to change the values of lightining_label according to time ranges. But the tables come out wrong. I tried using between, to_date, cast, convert but none of them worked.

below is a sample of the output I get which shows wrong labels.

Advertisement

Answer

Thank you all, I have solved the query doing this:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement