2

I have generated timestamp using new Cassandra\Timestamp() in php. Now I want to add 2 hours to this generated time using php and then store it in the database (Cassandra).

Essentially I want to do something like this:

$dt= new Cassandra\Timestamp();
$new_dt= $dt+3*3600; //here 3 is in hours

$query=$session->prepare('INSERT INTO tracker_table(id,deadline)VALUES(?,?)');
       $session->execute($query,array('arguments'=>array(new \Cassandra\Uuid(),$new_dt)));

**HERE deadline column has datatype set as timestamp.

The problem I am facing here is $dt returns an object datatype so I can't add 3 hours to it directly. And even if I am able to somehow add 3 hours to it then cassandra is not accepting it as viable input.

So, is it possible to add 3 hours directly to cassandra timestamp this way or should I deal with time stored as strings in DB.

My endgame is to store a deadline and then compare the current time to the stored deadline and if current time is greater then execute some code. something like this:

 $current_time=time();
 if ($current_time>$deadline){echo "hello"; }
Kaustubh Lohani
  • 635
  • 5
  • 15

1 Answers1

2

This should do the work;

$now = time(); // get current timestamp
$new_dt = new Cassandra\Timestamp($now + (3 * 3600));
Ersoy
  • 8,816
  • 6
  • 34
  • 48
  • That worked Thanks !! However it would be great if you could tell me what that 0 is after the comma in the timestamp call. – Kaustubh Lohani Jun 10 '20 at 14:38
  • 1
    @Zeek it's for microseconds - by default it is zero, you don't have to put that(it still works), sorry for confusion. Edited it for clarity – Ersoy Jun 10 '20 at 14:43