I am creating a new website and so far everything is working perfect but I have one small issue and i am wondering if anyone knows a way to sort it out.

Users come to my site to generate pin codes for my applications now this works perfect the pins are saved to a db with a created\_at time and then an expires\_at time with is creation time + 3 hours.

It works perfect most of the day but I run into issues when it gets to about 9:30 pm every day.

When you create a pin around 9:30 the creation time will be:

`9:23:43`

Now then expiration time will be 

`00:23:43`

and this is where the issue is when they add the pin to my applications. It checks them from the database by comparing the current time by creation time using the code below:

```
    <?php
include 'inc.db.php';
include 'inc.clear.php';
date_default_timezone_set('Europe/London');

function Check($key, $pin){

    global $mysqli;

    $time = date("H:i:s");

    $stmt = $mysqli->prepare("SELECT expired FROM tbl_pins WHERE key=? AND pin=?");
    $stmt->bind_param('ss', $key,  $pin);
    $stmt->execute();
    $stmt->bind_result($expired);

    while($stmt->fetch()) {
        if($time >= $expired){
            $result = 'Pin Expired';
            Clear($pin);
        }else{
            $result = 'Pin Verified';
        }

    }  

    $stmt->close();

    return $result;
}

?>

```

but as it checks the pin, the current time will be 

`22:10:30` and it checks to see if this is above the expiration time but that's `00:24:22` so because it's after 12am, it's always a lower number.

Does anyone know a way around this?