A
A
Archakov Dennis2016-05-18 16:48:40
PHP
Archakov Dennis, 2016-05-18 16:48:40

How to select a record by timestamp?

Hello, you need to make a selection of entries for today and tomorrow.
a711e0e009df41f1834e07115b060528.png
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

1 answer(s)
P
Pshkll, 2016-05-18
@Pshkll

$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 question

Ask a Question

731 491 924 answers to any question