Format Date

Format Date

aswebtechnologyaswebtechnology Posts: 19Questions: 0Answers: 0
edited May 2012 in General
Hi,
I am having a datetime column in my mysql table.

In datatable the date is showing as 2012-05-12 21:54:24. But I want to display it as May 12, 2012 21:54:24.

How can I do this? Anybody if knows, please help me in achieving this.

Thanks in advance.

Replies

  • SanjaySanjay Posts: 6Questions: 0Answers: 0
    edited June 2012
    My suggestion would be to edit the output section of the processing file for a special output near:
    [code]
    if ( $aColumns[$i] == "version" ) {
    /* Special output formatting for 'version' column */
    $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
    }
    [/code]

    So something like...
    [code]
    if ( $aColumns[$i] == "your_date_field" ) {
    /* Special output formatting for 'your_date_field' column */
    $date = strtotime($aRow[$i]);
    $format_date = date('d-m-Y', $date);
    $row[] = $format_date;
    } else if ( $aColumns[$i] != ' ' ) {
    /* General output */
    ...
    ...
    }
    [/code]
    Note: your_date_field above will be the same field name you have specified in the:
    [code]
    $aColumns = array( '...', '...', 'your_date_field', '...');
    [/code] (near the top of your page)

    Then checking the examples here (http://php.net/manual/en/function.date.php) and changing 'd-m-Y' in the date() function above will let you get the exact format you want the date to be in.

    Have a look at "Example #4 date() Formatting" it should have the date format you want.
  • aswebtechnologyaswebtechnology Posts: 19Questions: 0Answers: 0
    Thanks a lot for enlightening me my friend. Really appreciate your help.
This discussion has been closed.