Jump to content

[SOLVED] Unix time comparison


wsantos

Recommended Posts

I am trying to select records within a day interval. However the comparison of the timestamp seems not to work. uniquied is timestamp. Could anyone help me on this. Thanks

 

// Read form

  if(empty($_POST['StartDate']))
  {
    $startyear = date("Y");
    $startmonth = date("m");
    $startday = date("j");
    $endyear = date("Y");
    $endmonth = date("m");
    $endday = date("j");
    
    $strstartdate = $startyear . "-" . $startmonth . "-" . $startday . " 00:00:00";
    $strenddate = $endyear . "-" . $endmonth . "-" . $endday . " 23:59:59";
    $startdate = mktime(0,0,0,$startmonth,$startday,$startyear);
    $enddate = mktime(23,59,59,$endmonth,$endday,$endyear);
  }
  else
  {
    $pststartdate = $_POST['StartDate'];
    $pstenddate = $_POST['EndDate'];
    list($startmonth, $startday, $startyear) = split('[/.-]', $pststartdate);
    $strstartdate = $startyear . "-" . $startmonth . "-" . $startday . " " . "00:00:00";
    list($endmonth, $endday, $endyear) = split('[/.-]', $pstenddate);
    $strenddate = $endyear . "-" . $endmonth . "-" . $endday . " " . "23:59:59";
    $jd = gregoriantojd($startmonth,$startday,$startyear);
    $startdate=jdtounix($jd);
    $jd = gregoriantojd($endmonth,$endday,$endyear);
    $enddate=jdtounix($jd);
  }

// Connect to Table
  $conAsteriskCDR = mysql_connect("ip","user","password");
  if(!$conAsteriskCDR)
  {
    die('Could not connect: ' . mysql_error());
  }
  $dbAsteriskCDR = mysql_select_db("asteriskcdr",$conAsteriskCDR);

// Trying to get all activity for that given date from AsteriskCDR.
  $qryAsteriskCDR = "SELECT a.uniqueid,a.cname,q.action from anis a LEFT OUTER JOIN queue_actions q ON a.uniqueid=q.uniqueid where a.cname like '%PAF DISH G%' and from_unixtime(a.uniqueid)>" . $startdate . " limit 5";

  $result = mysql_query($qryAsteriskCDR,$conAsteriskCDR);
  if(!$result)
  {
    $message = 'Invalid query: ' . mysql_error() . '\n' . 'Whole query: ' . $qryAsteriskCDR;
    die($message);
  }

  while($data = mysql_fetch_array($result, MYSQL_ASSOC))
    $dataarr[] = $data;

// Terminate Connection
  mysql_close($conAsteriskCDR);

Link to comment
Share on other sites

got it solved.thanks here is my solution..

 

$qryAsteriskCDR = "SELECT a.uniqueid,a.cname,q.action from anis a LEFT OUTER JOIN queue_actions q ON a.uniqueid=q.uniqueid where a.cname like '%PAF DISH G%' and from_unixtime(a.uniqueid)>=from_unixtime(" . $startdate . ") and from_unixtime(a.uniqueid)<from_unixtime(" . $enddate . ")";

 

Just wondering if there is anyway i can further speed this up. This tables contain billions of records each. Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.