Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
Please don't mark this as the duplicate. I found many answers to check if string is of type date without adding any jquery libraries.But Couldn't find anything. 



JavaScript
function IsDate() { var date = "26.02.2016 11:48:36"  return Date.Parse(new Date("26.02.2016 11:48:36")); }


C#
The above code says the date is invalid but it is a valid date. Can any one please let me know how to check this kind of string value as date type in Jquery/Javascript? 


What I have tried:

C#
Many Solutions suggested to use Date.Parse() method or use datejs external library. For the string "26.02.2016 11:48:36" but the Date.Parse() method returns "Nan" where as it had to say as valid date.
Posted
Updated 21-Jul-20 21:27pm

JavaScript Date.parse() accepts dates in RF 2822[^] or https://www.w3.org/TR/NOTE-datetime format - your string is none of them...
 
Share this answer
 
Hello there!

Few things you should mind:
> Date.Parse is not a valid javascript function instead of use Date.parse and this return no. of millseconds between 1/1/1970 and to specified date.

> Javascript doesn't support dd/mm/yyyy format. So, your code might return Invalid date. So, use mm/dd/yyyy format instead of that.

JavaScript
var date = "02.26.2016 11:48:36"  

	if(!isNaN(Date.parse(date)))
	{
		document.write("Valid Date \n");
	}
 
Share this answer
 
v2
Date.parse("any string that constians a number 5") will give you a number
 
Share this answer
 
Hello,

I don't think Date.parse is correct to use. As referred from this link, The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31).

Rather, I would suggest you use moment.js. This library would help you to parse the Date more efficiently.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900