Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member tibberous's Avatar
    Join Date
    Aug 2003
    Posts
    195
    Member #
    2535
    Alright, I am trying to let the user select a range of dates. I then need to be able to check to see if a date is inside that range. What format should I use to compare them? I was thinking of using timestamps as returned by mktime but I don't think they would work with an inclusive range because of the time information. Should I just treat month, day and year seperate or is there a good function to compare dates? Seems like PHP always has the functions you need, just dunno where they are...

    Thanks!

  2.  

  3. #2
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Use timestamps, it is by far the easiest way to go about it.

    Not exactly sure what you are trying to do though, but if you are checking that a date is between two other dates then use an if statement like so:

    PHP Code:
    if ($timestamp1 $timestamp2)
    {
    if (
    $timestamp2 $timestamp3)
    {
    echo 
    "in range";
    }
    else
    {
    echo 
    "out of range";
    }
    }
    else
    {
    echo 
    "out of range";

    Use strtotime() to convert dates to timestamps:

    PHP Code:
    $timestamp1 strtotime("January 1 2004");
    $timestamp2 strtotime($datefromform);
    $timestamp3 strtotime("January 31 2004"); 
    JR

  4. #3
    Senior Member tibberous's Avatar
    Join Date
    Aug 2003
    Posts
    195
    Member #
    2535
    Thanks JR! Thats exactly what I needed and MUCH easier than trying to write my own.

  5. #4
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    No problemo
    JR


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:19 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com