Solved

Datatables date format problem

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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 …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

756 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