0

I am hoping someone has figured out the issue I am having. I have an ajax call to my MySQL database. I am using ColdFusion and jQuery datatables to display my fields. Everything works fine except when I try to format the date. I have tried to use <cfset> to format the date prior to the JavaScript and I have tried a number of other solutions found online. Below is my code.

$(document).ready(function() {
  var table = $('#TableData').dataTable({
    "bProcessing": true,
    "bStateSave": true,
    "bServerSide": true,
    "sAjaxSource": "MyCFMCall.cfm",
    "aoColumns": [{
        "sName": "ID",
        "sClass": "hidden"
      },
      {
        "sName": "DATABASE_DATE",
        "sTitle": "APP DATE",
        "bSortable": "true"
      } //<!---My timestamp from the database--->

    ],

    "columnDefs": [

      {
        "render": function(data, type, row) {
          return "+row[1]+";
        }, //<!---This will render the timestamp only, yet not formated.--->
        "targets": 1
      }
    ],
  });
});

If anyone can show me how to format this rendered timestamp into a more readable format I would really appreciate it.

user9263373
  • 1,054
  • 8
  • 15
Eddie B
  • 57
  • 7
  • 1
    What's in your `MyCFMCall.cfm` code? You can either format the date using the mySQL [**DATE_FORMAT**](https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format) function or you can use ColdFusion [**DateFormat**](https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-c-d/DateFormat.html) function. – user9263373 Feb 18 '18 at 21:27

1 Answers1

1

you should look into moment.js for parsing the timestamp. maybe this answer would be of some help Convert Date from one format to another format in JavaScript

Also, if you could tell me what format is the date actually in when you recieve it from the server? and do look into the 2nd answer there to avoid using a library.

zetawars
  • 1,023
  • 1
  • 12
  • 27
  • Yes, he has multiple options to format the date, but since he can format it server side, it won't require including a new js library if not needed. – user9263373 Feb 18 '18 at 21:28
  • there are also a few functions written in javascript available on that page. if he really wants to do it in jquery he can look into that. – zetawars Feb 18 '18 at 21:31
  • Thank you for the advice, I was able to get it done by adding the following to the query. DATE_FORMAT(YOURDATESTUFF,'%Y-%m-%d %r') AS SortOrderDate – Eddie B Feb 19 '18 at 03:34