5.6 Dates and Times

5.21

select
    pickup_datetime,
    dropoff_datetime
from
    nyc_yellow_taxi_0601_0615_2016
where
    tip_amount > 0
    and trip_distance > 2
limit
    5

5.22

select
    to_char(pickup_datetime, 'DD Mon YYYY') as start_date,
    to_char(dropoff_datetime, 'DD Mon YYYY') as end_date
from
    nyc_yellow_taxi_0601_0615_2016
where
    tip_amount > 0
    and trip_distance > 2
limit
    5

5.23

select
    to_char(pickup_datetime, 'D Month YYYY') as start_date,
    to_char(dropoff_datetime, 'D Month YYYY') as end_date
from
    nyc_yellow_taxi_0601_0615_2016
where
    tip_amount > 0
    and trip_distance > 2
limit
    5

5.24

select
    to_char(pickup_datetime, 'Day, Month FMDDth, YYYY') as start_date,
    to_char(dropoff_datetime, 'Day, Month FMDDth, YYYY ') as end_date
from
    nyc_yellow_taxi_0601_0615_2016
where
    tip_amount > 0
    and trip_distance > 2
limit
    5

5.25

select
    dropoff_datetime - pickup_datetime as duration
from
    nyc_yellow_taxi_0601_0615_2016
where
    tip_amount > 0
    and trip_distance > 2
limit
    5

5.26

select
    extract(
        dow
        from
            pickup_datetime
    ) as day_of_week,
    extract(
        hour
        from
            pickup_datetime
    ) as hour_of_day
from
    nyc_yellow_taxi_0601_0615_2016
where
    tip_amount > 0
    and trip_distance > 2
limit
    5