Calculate Age on The Fly

Calculate Age on The Fly

rmattesichrmattesich Posts: 2Questions: 0Answers: 0
edited March 2013 in Feature requests
Does anyone have some server or client code that takes Birthdate, in standard MySQL date format (yyyy-mm-dd) format, calculates, and displays Age as an integer using DataTable/Editor? (Or suggestion on how to do it efficiently?).
Thanks a lot,
Rom
Punta Gorda, FL

Replies

  • allanallan Posts: 55,108Questions: 1Answers: 8,653 Site admin
    edited March 2013
    You could use something like this:

    [code]
    mData: 'date', // property name
    mRender: function (data, type, row) {
    return prettyDate( data );
    }
    [/code]

    where `prettyDate` is something like John Resig's date formatter: http://ejohn.org/blog/javascript-pretty-date/ .

    If you want age as an integer, a modification to that basic idea (calculate current date, calculate date object for data, extract difference and return years) would be possible.

    Allan
This discussion has been closed.