Question: I'm new in mysql and I'm currently having an issue with a query. I need to get an average duration for each activity each day within a week. The date format is like: '2000-01-01 01:01:01', but I want to get rid of the 01:01:01 thing and only care about the date. How do I do that?

The table is something like this:

```
record_id   int(10)      NOT NULL,
activity_id varchar(100) NOT NULL,
start_time  datetime     NOT NUll,
end_time    datetime     NOT NULL,
duration    int(10)      NOT NULL;

```

Thanks.

Answer: 
I would suggest implementing a custom HandleErrorAttribute action filter.

See this link for more details:  

<http://msdn.microsoft.com/en-us/library/dd410203%28v=vs.90%29.aspx>

Setting up a HandleErrorAttribute action filter gives you complete control over which actions are handled by the filter, and it's easy to set at the controller level, or even at the site level by setting it up on a custom base controller, and having all of your controllers inherit from the base controller.

Something else I do with this, is I have a separate HandleJsonErrorAttribute that responds to Ajax calls by returning a Json response, rather than the custom page.

**UPDATE:**

Per some questions below, here is an example of a `HandleJsonErrorAttribute` that I use:

```
public class HandleJsonErrorAttribute : HandleErrorAttribute
{
    public override void OnException(ExceptionContext filterContext)
    {
        var serviceException = filterContext.Exception as ServiceException;

        filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

        filterContext.Result = new JsonResult { Data = new { message = serviceException == null ? "There was a problem with that request." : serviceException.Message } };

        filterContext.ExceptionHandled = true;
    }
}

```

And here is the jQuery that I use to handle these unhanded exceptions:

```
$(document).ajaxError(function (event, jqXHR, ajaxSettings, thrownError) {
    showPopdown($.parseJSON(jqXHR.responseText).message);
});

```

This allows my Ajax methods to be very lightweight -- they just handle returning normal Json, and in the event of an unhanded exception, a message w/ an error status code gets wrapped in Json and returned.

Also, in my implementation, I have a custom `ServiceException` that I throw from services, and this sends the message from the service layer instead of a generic message.
The easiest way I think you can do that is using the elmah library.

Take a look at this: <http://code.google.com/p/elmah/wiki/MVC> and this 
<http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx>