Good Day!
I am newbie into writing a program,
I need to get the timestampdiff between my 2 column with data type as datetime-local.
below is a sql query that suitable syntax to get the outage duration
SELECT timestampdiff(hour,DateStarted,DateRestored) as Outage from network_outage
however I have no idea how to insert this one in to my database I am using codeigniter framework
see below model code
function get_networkoutage($OutageDuration)
{
$this->db->select('timestampdiff(DateStarted,DateRestored) as OutageDuration',$OutageDuration);
$query = $this->db->get('network_outage');
return $query;
}
below is my Controller code
$data['NetworkOutage'] = $this->network_model->get_networkoutage($OutageDuration);
after echoing NetworkOutage in view page it gives me an error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: OutageDuration
Filename: controllers/Site.php
Line Number: 59
Backtrace:
File: D:\xampp\htdocs\itsystem\application\controllers\Site.php
Line: 59
Function: _error_handler
File: D:\xampp\htdocs\itsystem\index.php
Line: 315
Function: require_once
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DateStarted, DateRestored) as OutageDuration FROM `network_outage`' at line 1
SELECT timestampdiff(DateStarted, DateRestored) as OutageDuration FROM `network_outage`
Filename: D:/xampp/htdocs/itsystem/system/database/DB_driver.php
Line Number: 691
Thank you and best regards,