SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking X days out

    I need some JS code that will let me check and see if the date the user enters is within certain guidelines. ie...(no less than 2 days out and no more than 90 days out.)

    Someone was kind enough to give me this code, but I can't get it to work correctly. Everything always returns false. If I am reading this write, if it returns false, then the conditions are not met.

    Any ideas?

    Chris

    Code:
     
    function compareDates(myDate, min, max)
    {
    		var now = new Date().getTime();
    		var then = new Date(myDate).getTime();
    		var diff = (now - then) / 86400000;
    		var valid = true;
    	
    		var min = min * 86400000;
    		var max = max * 86000000;
    	
    		if (diff <= min || diff >= max) {
    				alert(diff + " " + min + " " + max);
    				return false;
    		}
    		return valid;
    }
    new compareDates("08/10/03", 2, 90);

  2. #2
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this is not what you are asking for first since it is php and also since you are probably checking "prior" to storing and this code is in the "pull" when the code is being called for display.

    <b><center>NEIGHBORHOOD CALENDAR</center></b>
    <?php
    include("/home/edshuck/secure/admin.inc");
    $Today=date("Y-m-d");
    //query the db
    $query = "select * from neighborhood"
    . " where date >= '$Today'"
    . " and date < DATE_ADD('$Today', interval 7 day)"
    . " order by date ";
    $result= mysql_query($query)
    or die ("Cannot execute query");
    //print the data in row, field and interate
    // Display the text of each entered row in a paragraph
    while ( $row = mysql_fetch_array($result) ) {
    $date=$row["date"];
    $message=$row["message"];
    $neighborhood_id=$row["neighborhood_id"];
    echo("<h5><b>");
    print($date);
    echo("</b> ");
    $message = str_replace("\r","",$message);
    $message = str_replace("\n\n","",$message);
    $message = str_replace("\n","",$message);
    $message = str_replace("[B]","",$message);
    $message = str_replace("[EB]","",$message);
    print(substr($message, 0, 130));
    echo('<a href="more.php?class=');<BR>echo($neighborhood_id);<BR>echo('">(more...)</a><br />');
    echo('</h5>');
    }
    ?>

  3. #3
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Yea, unfortunately, it MUST be JavaScript.

    Chris


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
  •