Get the 1st record and last record of a day in PostgreSQL
SELECT DISTINCT 
    DATE_TRUNC('day', Createdtime) "Created date",
    MIN(Createdtime) OVER (PARTITION BY DATE_TRUNC('day', Createdtime)) "1st record",
    FIRST_VALUE(Value)  OVER (PARTITION BY DATE_TRUNC('day', Createdtime)
                              ORDER BY Createdtime ASC) "1st Value",
    MAX(Createdtime) OVER (PARTITION BY DATE_TRUNC('day', Createdtime)) "last record",
    FIRST_VALUE(Value)  OVER (PARTITION BY DATE_TRUNC('day', Createdtime)
                              ORDER BY Createdtime DESC) "last Value",
    FIRST_VALUE(Value)  OVER (PARTITION BY DATE_TRUNC('day', Createdtime)
                              ORDER BY Createdtime ASC)
    -
    FIRST_VALUE(Value)  OVER (PARTITION BY DATE_TRUNC('day', Createdtime)
                              ORDER BY Createdtime DESC) "diff in Value"
FROM sourcetable