SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict kiltman's Avatar
    Join Date
    Mar 2004
    Location
    scotland
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date Compare Problems

    having problems with the following code, i know whats wrong but don't know how to fix it

    Code:
    function validate(thisform)
    {
        verified = true;
    
    
        if (arrive_day > monthdate[arrive_month])
        {
          alert("Error: There are only " +  monthdate[arrive_month] + " days in " + montharray[arrive_month]);
          //return false;
        }
        if (validateDate(arrival_date) == false)
        {
        	return false;
        }
        
        return true;
    
    }
    
    
    function  validateDate(dateString)
    {
        var today = new Date();
        today = today.getDate() + "/" + (today.getMonth()+1) + "/" + today.getFullYear();
    
    //need help to format dateString so it is the same format as todays string; as it doesnt work
    //when dates are like 1/3/2004 needs to be like 01/03/2004 to validate
        alert(dateString + " should be less than " + today);
        if (dateString < newtoday)
        {
          alert("Date is behind todays date, please correct");
          return false;
        }
        else
        {
        	return true;
        }
    
    }
    anyone have any ideas, or better suggestions on how to do it? thanks

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    The Date object constructor can handle a myriad of formats, so why don't you try creating a new Date() with the dateString:

    newDateString= new Date(datestring);

    and then do this on newDateString:

    today = today.getDate() + "/" + (today.getMonth()+1) + "/" + today.getFullYear();

    to get the format you want.

  3. #3
    SitePoint Addict kiltman's Avatar
    Join Date
    Mar 2004
    Location
    scotland
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey thanks, i managed to get it to work, after hours off playing around with the code


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •