Solved

Datatables date format problem

Posted on 2013-12-10
3
599 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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)

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now