-1

I want to know if I can create a function that can read a variable and if it's a date convert it to dd/mm/yyyy and when it's not a date it must do nothing

The date is in this format

2011-11-16T16:48:34.743

In my case i do have this code : (I have to read colomns name and if is egal then i take the value of the variable the problem is that when it take date i can format it )

  if (type == "TASK") {
            for (var key in ticket.task) {
                if (key == result) {
                        Val = Val.replace(item, ticket.task[key]);
                }
            }
        }

i have to replace a word with a value in the scope ticket.task[key] the method match doesn't work with ticket.task[key]

1 Answers1

0

try this:

var s = "2011-11-16T16:48:34.743";
try {
  var d = new Date(s);
  var formated = d.getDate() + '/' + (d.getMonth() + 1) + '/' + d.getFullYear();
} catch (e) {
  alert("not a date");
}

EDIT this is wrong, new Date() will not throw

phylax
  • 2,034
  • 14
  • 13