Comparing timestamps in PHP
NickName:Aaron Ask DateTime:2011-09-17T22:17:40

Comparing timestamps in PHP

How would I be able to return a boolean expression of true once exactly 24 hours have passed and no more?

I am using strtotime() to out put these two times:

$time1 = 1316268919;
$time2 = 1316268898;

Copyright Notice:Content Author:「Aaron」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7455411/comparing-timestamps-in-php

Answers
EdoDodo 2011-09-17T14:20:46

This should do what you need:\n\nif (($time1-$time2) == 86400) {\n // Exactly 24 hours have passed.\n}\n",


Oliver Charlesworth 2011-09-17T14:20:01

strtotime() returns the number of seconds since the Unix epoch. So to find the difference in times, simply subtract one from another. Then compare that difference against the number of seconds in 24 hours (24 * 60 * 60).",


goto-bus-stop 2011-09-17T14:22:41

abs($time1 - $time2) === 60 * 60 * 24\n\n\nthe abs is just in case; time2 might be bigger than time1.\n\nIf the difference in times equals 60 (seconds in a minute) * 60 * (minutes per hour) * 24 (hours for a day) = 86400, there's a day difference",


More about “Comparing timestamps in PHP” related questions

PHP comparing UNIX timestamps

I've having an issue comparing two unix timestamps in php. $time_now = mktime(); if($auction->time_end > $time_now){ //true } else{ //false } $auction->time_end is 1362579127 and set ..

Show Detail

Comparing Timestamps in PHP/Javascript

I'm developing a web based app that checks for updates on the server and notifies the user if there are any. This is an alternative to the push method; the background process in the app checks the ...

Show Detail

PHP Comparing Timestamps

When trying to compare to php timestamps I seem to be getting an off value. Not sure what I am missing. I would like my output to end up being something like 3days 5hours 10min since x I am trying

Show Detail

MySQL: comparing datetime with timestamps

I am comparing datetimes with timestamps since MySQL does support that. Let's say there is a record created at datetime B, and I have two timestamps A and C which A is 2 mins earlier and C is 2 mins

Show Detail

Comparing mysql timestamps

I am trying to compare timestamps by finding out if particular timestamp field is greater than 15 days ago. So if I try this on my database, I get: SELECT DATE_SUB(NOW(), INTERVAL 15 DAY) // 2012...

Show Detail

Comparing timestamps in Spark Scala

I have two columns in my db, called start_date and end_date, which are both timestamps. I want to collect only the rows that meet the requirement: start_date <= current date and end_date > cu...

Show Detail

comparing timestamps

HI, My php is very rusty and I can't quite remember how to do this. I have a script that i only want to call every 15 minutes. I've created a table called last_updated. What I want to do is have s...

Show Detail

Comparing timestamps in java

I receive timestamps in the form of Strings. I want to sort these timestamps. If the format of the timestamps is "yyyy-MM-dd HH:mm:ss.SSS", do I just compare them as Strings using compareTo function?

Show Detail

Timestamps and Logic in PHP

I'm building a system that queries a table of GPS coordinates and timestamps. The end goal is to deliver the user with a list of GPS points that were logged an hour before or an hour after of their

Show Detail

Comparing many timestamps with pandas

I have two dataframes with different sizes containing timestamps. I need to find nearest timestamps. In df A I need to find all first timestamps after any of timestamps of df B. The dataframes have...

Show Detail