0

I want convert VBscript into JavaScript, which checks whether date is valid or not. In VBscript they have used isDate builtin function which is not in having JavaScript. my date format is (mmm d,yyyy) ex : May 14,2015 VBscript :

sub CheckDateClient(sender, args)

    if isDate(args.value) then
        args.IsValid = True
    else
        args.IsValid = False
    End If
end sub

Please help me in converting this or any other script which can perform desitred requirement

George
  • 36,413
  • 9
  • 66
  • 103
  • 1
    possible duplicate of [Is this a good way to check for a valid date in JavaScript?](http://stackoverflow.com/questions/10263103/is-this-a-good-way-to-check-for-a-valid-date-in-javascript) – thewatcheruatu May 14 '15 at 20:24

3 Answers3

0

you can try using isDate() from Underscore JS library.

Link to source: http://underscorejs.org/#isDate

Something like this:

var is_date = _.isDate(myDate);
SpartaSixZero
  • 2,183
  • 5
  • 27
  • 46
0

The easiest thing to do is use the moment.js library. It's great for a number of things when manipulating dates. Works in the browser and in node.js.

http://momentjs.com/docs/#/parsing/is-valid/

CargoMeister
  • 4,199
  • 6
  • 27
  • 44
0

This code is working for me...........Thanks for responses

 function checkEnteredDates(stdateval, endateval) {

        var beginDt = new Date(stdateval);
        var endDt = new Date(endateval);

        if (beginDt > endDt) {
            return true;
        }
        else {
            return false;
        }
  • One thing to point out is that if your beginDt is less than or equal to your endDt, which is the case most of the time, then you will get false when you should be getting true. Assuming that you're checking that stdateval and endateval are valid dates. – SpartaSixZero May 26 '15 at 20:01