Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing timestamp to current time from database

Tags:

php

I need to test current time against a datetime from database, if it has been 30 mins then execute code, if not then dont. This is where I am at and I am stuck:

$link = mysqli_connect("hostname", "username", "password", "database"); $q = "SELECT id FROM dwCache ORDER BY id DESC LIMIT 1"; $qu = mysqli_query($link, $q);  while($row=mysqli_fetch_array($qu, MYSQL_ASSOC)){         $id = $row['id'];         $cache = $row['cache'];         $timest = $row['time'];     }  $newTime =  $difference = $timest if($timest >= ) 

As you can see towards the bottom I lose it as I am not sure what to do.

$timest returns : 2013-02-01 12:36:01 as the format Y-m-d h-i-s

Apologies on double post, other deleted.

like image 401
Josh Boothe Avatar asked Feb 01 '13 13:02

Josh Boothe


People also ask

How do you compare timestamp and time?

To perform assignments and comparisons between dates and timestamps or times and timestamps, you can use the SQL functions DATE, TIME, and TIMESTAMP, which convert values from one type to another. There might be situations when it is not practical for you to use these functions.

Can we compare date with timestamp in SQL?

A date, time, or timestamp value can be compared with another value of the same data type, a datetime constant of the same data type, or with a string representation of a value of that data type. Additionally, a TIMESTAMP WITHOUT TIME ZONE value can be compared with a TIMESTAMP WITH TIME ZONE value.

How do I compare timestamps in pandas?

Comparison between pandas timestamp objects is carried out using simple comparison operators: >, <,==,< = , >=. The difference can be calculated using a simple '–' operator. Given time can be converted to pandas timestamp using pandas. Timestamp() method.


1 Answers

First convert $timest to timestamp

$time = strtotime($timest);  $curtime = time();  if(($curtime-$time) > 1800) {     //1800 seconds   //do stuff } 
like image 87
Sankalp Mishra Avatar answered Sep 27 '22 19:09

Sankalp Mishra