Jump to content

How to pull YYYY from 'DATE' & Sum of Hours


adriscoll

Recommended Posts

Hello.

 

I am having difficult combining 2 functions.  On their own, each works fine.

 

I would like to sum all of the hours within a certain event type based on the current year.

 

Year = in table as DATE type and formatted as 2011-05-01.

 

My current code to sum the hours is:

<?php

include('dbconfig.php');

// Make a MySQL Connection
mysql_connect("localhost", "$user", "$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());

$result = mysql_query("SELECT sum(hours) AS total_hours FROM event_schedule Where park = 'ParkA' ") or die(mysql_error());

while($row = mysql_fetch_array($result)) {
echo "Hours Worked: ";
echo $row['total_hours'];

}

?>

 

I was thinking of combining that with something similar to what's below but don't know how to.


<?php 
$cur_year = date("Y");                           

echo $cur_year;
?>

 

Thank you in advance.

Link to comment
https://forums.phpfreaks.com/topic/238252-how-to-pull-yyyy-from-date-sum-of-hours/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.