function inside jade template undefined

I have the following function inside a jade template:

-function prettyDate(dateString){
    -var date = new Date(dateString);
    -var d = date.getDate();
    -var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
    -var m = monthNames[date.getMonth()];
    -var y = date.getFullYear();
    -return d+' '+m;
-}

and this is called with the following code:

td #{prettyDate(c.dateStart)}

But I'm getting the error on that line:

undefined is not a function

Yet it clearly is a function. What am I doing wrong?

Here's the full jade template in case you're interested:

extends ../layout

-function prettyDate(dateString){
-var date = new Date(dateString);
-var d = date.getDate();
-var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
-var m = monthNames[date.getMonth()];
-var y = date.getFullYear();
-return d+' '+m;
-}

block content
    div#highlighted
        div.container
            div.row-fluid.header
                h2.page-title
                    span Courses
    div#content
        div.container.portfolio
            div.row
                div.span7.project-photos
                    each c in course
                        div.block.course-snippet
                            h3.block-title
                                span: a(href='/courses/#{c.shortTitle}') #{c.title}: #{c.type} (ages #{c.ageLow}-#{c.ageHigh})
                            dl
                                dt Dates
                                dd #{c.dateStart} - #{c.dateEnd}
                                dt Tutors
                                dd Names hidden
                                dt Fee
                                dd #{c.fee}
                                dt Course Description
                                dd #{c.shortDescription}
                            a.btn.btn-primary(href="/courses/#{c.shortTitle}") More details
                            |  
                            a.btn.btn-primary(href="/booking/#{c.shortTitle}") Book a place now
                div.span5.sidebar.sidebar-right
                    h3 Full Course Schedule
                    table#courses-table
                        thead
                            tr
                                td Start date
                                td End date
                                td Course
                                td Age range
                                td Fee (£)
                        tbody
                            each c in course
                                tr
                                    td #{prettyDate(c.dateStart)}
                                    td #{c.dateEnd}
                                    td
                                        a(href="/courses/#{c.shortTitle}") #{c.title}
                                    td #{c.ageLow}-#{c.ageHigh}
                                    td #{c.fee}

This has now been solved by moving the function to app.locals in the app.js file:

app.locals.prettyDate = function(dateString){
    var date = new Date(dateString);
    var d = date.getDate();
    var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
    var m = monthNames[date.getMonth()];
    var y = date.getFullYear();
    return d+' '+m;
}

The function is the usable in the template as described.