Answer the question
In order to leave comments, you need to log in
How to select a record by timestamp?
Hello, you need to make a selection of entries for today and tomorrow.
There is a JSON list of users, each user has a timestamp in which the reception is indicated for some day. And in my application, I display people for: today, tomorrow and that's it.
How to correctly calculate timestamp from one day and tomorrow?
You can use PHP or Swift.
Answer the question
In order to leave comments, you need to log in
$timestamp = "2016.09.02T13:34";
$today = new DateTime(); // This object represents 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";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question