Get the 1st record and last record of a day in PostgreSQL Below is the table structure:

| Createdtime              | Value
---------------------------|--------------
|2019-06-02 00:25:35.86+08 |7805165.31 Mb
|2019-06-02 00:03:52.645+08|7796650 Mb
|2019-06-02 05:16:30.108+08|7757693.25 Mb
|2019-06-02 05:41:25.737+08|7758570.94 Mb
|2019-06-02 05:32:17.743+08|7758576.31 Mb
|2019-06-02 05:59:59.817+08|7760187.25 Mb
|2019-06-02 05:50:47.463+08|7758511.81 Mb
|2019-06-03 11:19:54.337+08|7764680.25 Mb
|2019-06-03 11:42:35.448+08|7764677.63 Mb
|2019-06-03 11:54:08.578+08|7764681.63 Mb
|2019-06-03 12:18:19.116+08|7764683.63 Mb
|2019-06-03 12:30:52.553+08|7764686.63 Mb
|2019-06-03 22:57:51.778+08|7728657.13 Mb
|2019-06-03 23:12:38.93+08 |7735638.06 Mb
|2019-06-03 23:25:21.318+08|7706719.19 Mb


I want the output like this:

Created date | 1st time                   | 1st value  | last time                  | last value | value diff
-------------+----------------------------+------------+----------------------------+------------+-----------
2019-06-02   | 2019-06-02 00:25:35.86+08  | 7805165.31 | 2019-06-02 05:50:47.463+08 | 7758511.81 | -46653.5
2019-06-02   | 2019-06-03 11:19:54.337+08 | 7764680.25 | 2019-06-03 23:25:21.318+08 | 7706719.19 | -57961.06
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