How to select records by timestamp?

Hello, you need to do to select records for the current day and tomorrow.

a711e0e009df41f1834e07115b060528.png

A JSON list of users, each user has a timestamp indicating the reception on any day. And in my application I get people for today, tomorrow and for all.

How to calculate timestamp from one day and tomorrow?

Can option PHP or Swift.
July 9th 19 at 13:19
1 answer
July 9th 19 at 13:21
$timestamp = "2016.09.02T13:34";

$today = new DateTime(); // This object represents the current date/time
$today->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison

$match_date = DateTime::createFromFormat( "Y. m.d\\TH:i", $timestamp );
$match_date->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison

$diff = $today->diff( $match_date );
$diffDays = (integer)$diff->format( "%R%a" ); // Extract days count in interval

switch( $diffDays ) {
 case 0:
 echo "//Today";
break;
 case -1:
 echo "//Yesterday";
break;
 case +1:
 echo "//Tomorrow";
break;
default:
 echo "//Sometime";
}

Find more questions by tags PHPSwift