I want to create an attendance kind of table I get the value from punch machine like this : 

```
UID  |  Time
023  |  2019-01-29 20:06:53
023  |  2019-01-29 20:07:10
023  |  2019-01-29 20:22:05
123  |  2019-01-30 08:57:01
027  |  2019-01-30 09:14:14
023  |  2019-01-30 11:22:21
123  |  2019-01-30 18:35:53
027  |  2019-01-30 19:00:25

```

Now all the entries in one table so I want the first and last entry of user and group by date then get time difference from 2 values 

I need Output like this :

```
UID  |  In Time               |  Out Time              |  Time Diff.
023  |  2019-01-29 20:06:53   |  2019-01-29 20:22:05   |  00:18:00
027  |  2019-01-30 09:14:14   |  2019-01-30 19:00:25   |  10:00:00
123  |  2019-01-30 08:57:01   |  2019-01-30 18:35:53   |  10:00:00

```

first i'm try to get data like this but this is not working for me

```
$select =  mysqli_query ($db, "SELECT *, Min(Date) AS MinDate, Max(Date) AS MaxDate FROM demotable GROUP BY UID");

```