Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to compare start date with today date and end date with start date .This function works fine in Google chrome but does not works in Mozilla firefox Why???
Dates are in Format dd-MMM-yyyy
JavaScript
function DateCheck(element, name) {
            var todaydate = new Date();
            var year = new Date().getFullYear();
            var month = new Date().getMonth();
            var firstDate = new Date(year, month, 1);
            var dateString1 = (document.getElementById("<%= txtStartDate.ClientID %>").value)
            var myDate1 = new Date(dateString1);
            var dateString2 = (document.getElementById("<%= txtEndDate.ClientID %>").value)
            var myDate2 = new Date(dateString2);
            if (myDate1 < todaydate) {
                alert('Start date must be greater than Today date.');
                document.getElementById("<%= txtStartDate.ClientID %>").value = "";
                return;
            }
            else if (myDate1 > myDate2) {
                alert('End date must be greater than Start date.');
                document.getElementById("<%= txtEndDate.ClientID %>").value = "";
                return;
            }
        }
Posted
Updated 5-Jun-16 19:26pm
v3
Comments
Kornfeld Eliyahu Peter 18-Nov-14 5:01am    
'not working' is not a good description of any problem...
Try to describe what you have and how it differs from what you have expected...
Do you got any error - share it!
Also! FF has one of the best JavaScript debugger, use it!
Neha Mukesh 18-Nov-14 6:38am    
var myDate1 = new Date(dateString1);
shows invalid date .could you please explain me now how to solve this problem
Kornfeld Eliyahu Peter 18-Nov-14 7:04am    
What the value of dateString1?
Neha Mukesh 18-Nov-14 7:24am    
datestring1=10-Nov-2014
Debug and see what's the issue.

You are passing a string that represents a date. Date object can not understand it without some help...
However JavaScript Data object has a helper method - parse()[^]...
Using it you can convert your string to JavaScript date...
JavaScript
var myDate1 = new Date(Date.parse(dateString1));
 
Share this answer
 
Comments
Manas Bhardwaj 18-Nov-14 8:01am    
yes +5
Kornfeld Eliyahu Peter 18-Nov-14 8:05am    
Thank you...
You can use
JavaScript
YOURDATE.replace(/-/gm, '/')
instead of
JavaScript
Date.parse(YOURDATE.replace('-', '/').replace('-', '/')
 
Share this answer
 
v2
C#
Javascript is best but weird.

Try following and you will not get Invalid date in any browser.

var NEWDATE = Date.parse(YOURDATE.replace('-', '/').replace('-', '/'));
                if (!isNaN(NEWDATE)) {
                    NEWDATE= new Date(NEWDATE);
                   console.log(NEWDATE.getDate());
                   }
 
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