Web Analytics Made Easy -
StatCounter Date not in the past - CodingForum

Announcement

Collapse
No announcement yet.

Date not in the past

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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; Feb 11, 2004, 06:02 AM.
    Dale Ellis
    __________________

  • #2
    http://devedge.netscape.com/library/...e.html#1194314
    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"

    Comment


    • #3
      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
      __________________

      Comment


      • #4
        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"

        Comment


        • #5
          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
          __________________

          Comment


          • #6
            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"

            Comment


            • #7
              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
              __________________

              Comment

              Working...
              X