Solved

Datatables date format problem

Posted on 2013-12-10
3
602 Views
Last Modified: 2013-12-10
I'm using datatables with my project and i'm trying to display several dates.

It works fine in Chrome but not in firefox. In firefox the dates are shown as Nan

Any ideas

Here's a link

http://cloud-contractor.co.uk/etest.php
0
Comment
Question by:maddisoncr
3 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39708374
Just so you know, in IE 11 it also displays NaN for the dates. NaN stands for "Not a Number".

I don't think this problem is with the date handling code because this:

<html>
<head>
<script>
function getValue()
  {
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var newdate= (curr_date + "/" + curr_month + "/" + curr_year);
alert(newdate);
}
</script>
</head>
<body>

<h1 id="myHeader" onclick="getValue()">Click me!</h1>

</body>
</html>

Open in new window


This works just fine in FF and IE 11.

Hope this helps.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39708392
replace :
							var d = new Date (data);
						
							var curr_date = d.getDate();
							var curr_month = d.getMonth() + 1;
							var curr_year = d.getFullYear();

							var newdate= (curr_date + "/" + curr_month + "/" + curr_year);
										
							if( (data)){
								return newdate;
							}
							else
							{
							return "";	
							}

Open in new window

by :
							if(data) {
								var d = data.split(/-|\s/);
							
								var curr_date = d[2];
								var curr_month = d[1];
								var curr_year = d[0];

								return curr_date + "/" + curr_month + "/" + curr_year;
							}
							else
							{
								return "";	
							}

Open in new window

0
 

Author Comment

by:maddisoncr
ID: 39708533
thank you guys for the quick responses :-)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question