0
    <html>
    <script language="javascript">
    function validate(dt1,dt2)
    {
    var jdt1=Date.parse('20 Aug 2000 '+dt1);
    var jdt2=Date.parse('20 Aug 2000 '+dt2);
    if(isNaN(jdt1))
    {
    alert('invalid start time');
    return false;
    }
    if(isNaN(jdt2))
    {
    alert('invalid end time');
    return false;
    }
    if (jdt1>jdt2)
    {
    alert('start is greater');
    }
    else
    {
    alert('start is less equal');
    }
    }
    </script>
    <body>
    <div>
    <form name=frm id=frm action=temp.php method="get" accept="text/csv">
    <P>&nbsp;</P>
    start <INPUT id=txt1 name=txt1 value='10:30:05 am'>&nbsp; <br>
    end <INPUT id=txt2 name=txt2 value='10:40:05 am'>&nbsp;
    <input type=button value=ok id=button2 name=button2 onclick ='validate(document.frm.txt1.value,document.frm.txt2.value)'>&nbsp;&nbsp;
    </P>
    </form></div>
    <script language='javascript'>
    </script>
    <div id="txtHint">&nbsp;
    </div>
    <P></P>
    </body>
    </html>

Any body help to get the differnce in munutes .

Edited by pritaeas: Un-Closed

2
Contributors
3
Replies
15
Views
2 Years
Discussion Span
Last Post by DaveAmour
1

Try this

    function validate(dt1, dt2)
    {
        var jdt1 = Date.parse('20 Aug 2000 ' + dt1);
        var jdt2 = Date.parse('20 Aug 2000 ' + dt2);
        var diffMs;
        var diffMins

        if (isNaN(jdt1))
        {
            alert('invalid start time');
            return false;
        }

        if (isNaN(jdt2))
        {
            alert('invalid end time');
            return false;
        }

        if (jdt1 > jdt2)
        {
            diffMs = (jdt1 - jdt2);

            diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes

            alert('start is greater by ' + diffMins + ' minutes');
        }
        else
        {
            diffMs = (jdt2 - jdt1);

            diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes

            alert('start is less equal by ' + diffMins + ' minutes');
        }

        return true;
    }

Edited by DaveAmour

0

Excellent DaveAmour, It is working..

Very Usefull code,

Very Thanks

0

Youre welcome. I also added return true since you were not doing that.

Edited by DaveAmour

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.