Search code examples
phpjsonunix-timestamp

How to check if UNIXTimeStamp is mid day time or evening in php


I have the JSON Response which contains DateTime in UNIXTIMESTAMP. I would like find that the time in JSON Response is of Mid Day time or evening.

Lets say below is the response and I want to check CloseTime weather it is mid day time or evening time.

{
    "gameName": "NUMBERS", 
    "id": "16440", 
    "status": "RESULTS_AVAILABLE", 
    "closeTime": "1491927615000"
}

Solution

  • This might work for you..decode your json and assign closeTime to $timestamp

     <?php
        $timestamp = 1491927615000;
        $date = date('H', $timestamp);
    
        if($date < 12){
    
             echo "good morning";
    
           }elseif($date > 11 && $date < 18){
    
             echo "good afternoon";
    
           }elseif($date > 17){
    
             echo "good evening";
    
           }
    
    
        ?>
    

    http://codepad.org/SCJw32FL