Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Date not in the past

    Whats the easyiest way to check that a date is not in the past?

    I want to check that my date is in this format "DD/MM/YYYY" and is not in the past.

    Is there a easy way to do this with RegEx.

    I was thinking of creating a new Date object and with the inputed value and then checking that new Date() is not create than it. However that will check from the exact second wont it, So how can I tructate it down?

    TIA
    Dale
    Last edited by ellisd5; 02-11-2004 at 12:02 PM.
    Dale Ellis
    __________________

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Im still having problems with this

    My current function is this
    Code:
    function isDate(sDateField) {
    	var selectedDate = new Date(sDateField.value);
    	var todaysDate = new Date();
    	todaysDate.setHours(0);
    	todaysDate.setMinutes(0);
    	todaysDate.setSeconds(0);
    }
    And its called here:
    Code:
    <INPUT TYPE="text" NAME="PAIRS_REQD_BY" CLASS="searchBox" onChange="isDate(this);">
    <a href="javascript:show_calendar('SW_FORM.PAIRS_REQD_BY',null,null,'DD\/MM\/YYYY');"><img src="/btwportal/framework/skins/bt_wholesale/images/calender.gif" ALT="Calender" border="0" width="18" height="17"/></a>
    The first problem is that I need to make sure that its in the correct format dd/mm/yyyy.

    The second is that I dont think that im converting the inputed value into a proper date as it wont let me do comparissons like what is greater than the other.

    And my third problem is that you can click the image next to it and bring up a calendar which sets the value in that textbox. I am unable to change the code in this but I still need to check that the date is today or in the future when I change the value using this.

    TIA
    Dale
    Dale Ellis
    __________________

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just create a new date and then make sure its value is a number, if not that means the string you supplied to Date constructor was incorrect:

    selectedDate = new Date(selectedDateStr);
    if(isNaN(selectedDate.valueOf()))
    { /* Process Error and return */
    }
    (todaysDate = new Date()).setHours(0,0,0,0); /*This can be one line of code, not 5 (you forgot to 0 milliseconds) */
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #5
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    This still does not solve the problem :-
    Code:
    function isDate(sDateField) {
    	var selectedDate = new Date(sDateField.value);
    	var todaysDate = new Date();
    	todaysDate.setHours(0,0,0,0);
    	if (isNaN(selectedDate.valueOf())) {
    		alert("Not a valid date");
    	} else {
    		if (todaysDate > selectedDate) {
    			alert("Yea");
    		} else {
    			alert("Nope");
    		}
    	}
    }
    This is the currecnt code.
    It doesn't like the this line
    Code:
    if (todaysDate > selectedDate) {
    Which suggestd to me that is not a proper date, even though it didn't error when its set.
    Also things like selectedDate.getFullYear() return what you would expect. So although its a date object, its sort of not

    Can anyone solve my problem?
    Dale Ellis
    __________________

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use todaysDate.valueOf() > selectedDate.valueOf()
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #7
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks Vladdy but its still not working but just figgured out why is not working!

    The xml parser thats creating the html/javascript has replaced my > with &gt; which is not working
    Dale Ellis
    __________________


  •  

    Posting Permissions

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