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 13 of 13

Thread: Date Problems?

  1. #1
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts

    Date Problems?

    I am having troubles with the below:

    PHP Code:
      $year  date("Y");
      
    $month date("n");
      
    $date  date("j");

      
    $count=$count+1;
      
    $date1=$row["date"];
      
    $year1=$row["year"];
      
    $month1=$row["month"];
                
      if(
    $month1=="1")
        { 
    $month2="January"; }
      else if(
    $month1=="2")
        { 
    $month2="February"; }
      else if(
    $month1=="3")
        { 
    $month2="March"; }
      else if(
    $month1=="4")
        { 
    $month2="April"; }
      else if(
    $month1=="5")
        { 
    $month2="May"; }
      else if(
    $month1=="6")
        { 
    $month2="June"; }
      else if(
    $month1=="7")
        { 
    $month2="July"; }
      else if(
    $month1=="8")
        { 
    $month2="August"; }
      else if(
    $month1=="9")
        { 
    $month2="September"; }
      else if(
    $month1=="10")
        { 
    $month2="October"; }
      else if(
    $month1=="11")
        { 
    $month2="November"; }
      else if(
    $month1=="12")
        { 
    $month2="December"; }
                    
                    
      if(
    $count <= $front_cols && $count==1){echo "";}
      else if(
    $count $front_cols && $count 1){echo "";}
      else if(
    $count==$front_cols){echo "";}
            
      if(
    $month1>=$month && $year1>=$year && $date1>=$date)
      {
        echo 
    "<tr><td><font size='$font_size'  face='$font_face'>".$month2." ".$date1.", ".$year1."</font></td>
       <td><font size='$font_size' face='$font_face'>"
    .$row["venu"]."</font></td>
       <td><font size='$font_size' face='$font_face'>"
    .$row["location"]."</font></td>
       <td><font size='$font_size' face='$font_face'>"
    .$row["time"]."</font></td>
       <td><font size='$font_size' face='$font_face'>$"
    .$row["tickets"]."</font></td>
       </tr>"
    ;
      }
      else
      {
        echo 
    "";
      } 
    I only want it to show the things that are coming up into the future and today, not ones that have happened already. However it just doesn't seem to be working. Any help?
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why don't you make the selection inside your query?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    So I can do it by
    PHP Code:
    $query=mysql_query("SELECT * FROM the_database WHERE $month1>='$month' AND $year1>='$year' AND $date1>='$date'"); 
    However if so, why did the last code bring up every listing there was anyway?
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #4
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    Well I seem to have got it working so it doesn't show past dates... kind of. It works however I am having trouble not showing past dates in the same month.

    if I use the query:
    PHP Code:
    $query=mysql_query("SELECT * FROM the_database WHERE $month1>='$month' AND $year1>='$year' AND $date1>='$date'"); 
    It will show me the dates from today and beyond... for example, show me dates on 2004 and next years coming... good. However with the date it will not show me the info on October 23 if todays date is 25, but we are still in September.... I think I explained this right, but ask if it needs clearing up because I would really liked this solved and I am totally lost.
    Last edited by dniwebdesign; 09-25-2004 at 08:06 PM.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    What format have are you using in the database for your date field (mysql date, int, char) ?

  • #6
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    I have the following rows in the forums...

    date
    month
    year
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #7
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    I presume you have your date data saved as numbers rather than text (ie 9 rather than September). If so, this may help...
    (not 100% certain can concatenate in a query)
    PHP Code:
    <?PHP
    $this_date 
    date("Y") . date("m") . date("d");  // produces 20040925

    $this_date $this_date 1// my silly way of making sure its an int and not a string

    $sql "SELECT * FROM the_database WHERE ((year . month . date) >= '$this_date')";

    ?>
    Lite...

  • #8
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    doesn't seem to work
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #9
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    hmmmm

    the problem may be that your month and date fields do not contain leading zeros, while the number you are comparing them against does use the leading zeros.

    I need to ponder a solution.

    Lite...

  • #10
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Try this...

    PHP Code:

    $this_year 
    date("Y");
    $this_month date("m");
    $this_date date("d");

    $this_year $this_year 1;
    $this_month $this_month 1;
    $this_date $this_date 1;


    $sql "SELECT * FROM the_database WHERE ((year  >= '$this_year') AND (month >= '$this_month') AND (date  >=  '$this_date'))"
    Lite...

  • #11
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Is there a specific reason you are choosing not to use either date type fields or timestamps for your date data?

  • #12
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could store the value returned from time(); in a int(11) field and then get all you want using the date(); function.

  • #13
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by litebearer
    hmmmm

    the problem may be that your month and date fields do not contain leading zeros, while the number you are comparing them against does use the leading zeros.

    I need to ponder a solution.

    Lite...
    No, the number I am using do not have leading zeros, nor do the numbers I'm comparing them to...

    as far as the other things... i don't know how they work yet...
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com


  •  

    Posting Permissions

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