Search code examples
phpsqldataformat

Calculate average of two data fields php/mysql


I wonder know how to deal data format. I have 2 columns date(starting date) *date2 (end date)*. I am not familiar with php/mysql.

one my biggest clue is the data/data2 fields appears on this format ie. "1394797440". I am trying to build a dashboard with DB graphics of a ticket support. Had some features done but the data format is stressing me up. let me know if I am right.

I need to do a foreach on both fields? sorry my noob question but I am totally lost :|

mostly I use this call-> $call_date = date("m/d/y",$site_calls->call_date);

I will really appreciate any help.


Solution

  • This is a UNIX epoch datetime format i.e. number of seconds elapsed since 1st Jan, 1970. To take average of the two dates, it is similar to any other numeric average.

    $avg_date = $site_calls->call_date + (($site_calls->call_date2 - $site_calls->call_date)/2);
    $call_date = date("m/d/y",$avg_date);