How to validate user input is current date and time?

In html i use datefield

 <ext:DateField runat="server"  ID = "date"  Format="Y-m-d hh:mm:ss" SubmitFormat="Y-m-d H:i:s"  MarginSpec="0 0 0 60" FieldLabel="Gate In Date/Time" AllowBlank="false" IndicatorText="*" IndicatorCls="red-text"/>

when it view it shows correct date but the time is always 12:00:00.In javascript i do it like this

var iframeID = $('iframe').attr('id');

var myDate = lazyMethod_get(iframeID, "formdetail", "date")
var today = new Date().toISOString().slice(0, 10);


if (myDate > today) {
    alert("Entered date is greater than today's date ");
else {
    alert("Entered date is less than today's date ");

the validation always alert the date entered less than today date. I just want to validate the date and time if the user insert for example 2016-02-03 the date is wrong and get current date.

Thank you.



Time in microseconds.

if (! { = function now() {
    return new Date().getTime();

Do your formatting after you do your calculations.

What is your lazyMethod_get() workings. Is it returning a string, or a Date object.


When you do:

new Date().toISOString().slice(0, 10);

toISOString generates a UTC date (i.e. the time zone offset is 00:00) so it may be a different date from the host system.

E.g. for a user in time zone +10:00 when it is 09:30 on 25 May, the above will return a date string for 24 May. Similarly, for systems where the offset is west of Greenwich, dates will be one day later for times in the evening (e.g. 20:30 on 25 May in time zone -04:00 will be 00:30 on 26 May UTC).


First - The Ext.NET DateField only returns a date (MM-dd-yyyy) not a time. The time always defaults to 12:00:00.

I would compare the year, day, and month of each.


    var isToday = function (field) {
        var fieldDate = field.getValue();
        var today = new Date()

        if ((today.getFullYear() + today.getMonth() + today.getDate())
            == (fieldDate.getFullYear() + fieldDate.getMonth() + fieldDate.getDate())) {
            return true;
        else {
            return false;


    <ext:DateField ID="DateField1" runat="server">
            <Select Handler="alert( isToday(#{DateField1}) )" />


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.