Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a asp:TextBox, in which the user inserts a date. Now I like to compare the month of the date with my current month and if it's older then the current month show a text.

JavaScript
function InsertProjectCharging() {
            var date = $('#<%=txtDateFrom%>').val();
            if (ParseInt(date.substring(3, 2)) < (now.getMonth() + 1)) $('.dateValidation').show();
            else {
                ......
            }
        }


Would be really nice, if someone could help me!

What I have tried:

I also tried it with Number(month) instead of parseInt
Posted
Updated 18-Sep-18 3:12am

1 solution

Work with them as dates

JavaScript
var now = new Date();
var date = $('#<%=txtDateFrom%>').val();
var ddate = new Date(date);

	if(ddate.getMonth() < now.getMonth() + 1)
		alert('true');
	else
		alert('false');



Please note your handling the of edge cases, in other words, you will need logic to also check the year.
 
Share this answer
 
v3
Comments
littleGreenDude 18-Sep-18 13:07pm    
Thanks for the down vote. How about adding a useful comment. If you work with them both as dates then the comparison works.
Maciej Los 18-Sep-18 14:30pm    
Sounds good to me.
+5!

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