在asp.net中使用javascript比较两个日期 [英] comparing two dates using javascript in asp.net

查看:70
本文介绍了在asp.net中使用javascript比较两个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果第一个文本框的日期不能少于第二个文本框的用户,则我有两个Ajax日历控件和两个文本框.用户应该使用Javascript输入的日期必须比第一个文本框的日期大.

请有人帮我

感谢Advance

I Have two Ajax Calendar Control and Two Textbox if the first textbox date should not be less than second textbox user should enter the date must be greater date from first text box using Javascript

Pls somebody help me

Thanks in Advance

推荐答案

我的朋友..为什么不搜索google ..只需尝试此链接即可.

http://stackoverflow.com/questions/6044632/problem-in-comparing-two-dates [ ^ ]

http://lokeshbasana.wordpress.com/2009/07/16 /comparing-two-dates-in-asp-net/ [ http://forums.asp. net/t/1693308.aspx/1?Javascript + code + to + compare + two + dates + in + Ajax + calender [
My friend.. Why you not search in google.. Just try this link its work.

http://stackoverflow.com/questions/6044632/problem-in-comparing-two-dates[^]

http://lokeshbasana.wordpress.com/2009/07/16/comparing-two-dates-in-asp-net/[^]

http://forums.asp.net/t/1693308.aspx/1?Javascript+code+to+compare+two+dates+in+Ajax+calender[^]


您可以使用此


you can use this


function CompareDates()
       {
            var fdate = document.getElementById('<%=txtAgValidFrom.ClientID%>');
            var edate = document.getElementById('<%=txtAgValidTo.ClientID%>');
            var FromDate = fdate.value.split('/');
            var EndDate = edate.value.split('/');
            var val = 'false';

            if (parseInt(FromDate[2]) < parseInt(EndDate[2])) {
                val = 'true';
                return true;
            }
            else if (parseInt(FromDate[2]) == parseInt(EndDate[2])) {
                if (parseInt(FromDate[0]) < parseInt(EndDate[0])) {
                    val = 'true';
                    return true;
                }
                else if (parseInt(FromDate[0]) == parseInt(EndDate[0])) {
                    if (parseInt(FromDate[1]) <= parseInt(EndDate[1])) {
                        val = 'true';
                        return true;
                    }
                }
            }
            if (val == "false") {
                alert("Agreement valid from date cannot be greater than Agreement valid to date");
                return false;
            }
        }


这篇关于在asp.net中使用javascript比较两个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆