...

View Full Version : Date Problems?

dniwebdesign
09-25-2004, 03:46 AM
I am having troubles with the below:

\$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?

raf
09-25-2004, 07:16 AM
why don't you make the selection inside your query?

dniwebdesign
09-25-2004, 06:03 PM
So I can do it by

\$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?

dniwebdesign
09-25-2004, 06:59 PM
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:

\$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.

litebearer
09-25-2004, 07:14 PM
What format have are you using in the database for your date field (mysql date, int, char) ?

dniwebdesign
09-25-2004, 07:18 PM
I have the following rows in the forums...

date
month
year

litebearer
09-25-2004, 07:36 PM
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
\$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...

dniwebdesign
09-25-2004, 07:45 PM
doesn't seem to work

litebearer
09-25-2004, 07:53 PM
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...

litebearer
09-25-2004, 08:04 PM
Try this...

\$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...

litebearer
09-25-2004, 08:06 PM
Is there a specific reason you are choosing not to use either date type fields or timestamps for your date data?

marek_mar
09-25-2004, 08:35 PM
You could store the value returned from time(); (http://www.php.net/time) in a int(11) field and then get all you want using the date(); (http://www.php.net/date) function.

dniwebdesign
09-25-2004, 11:14 PM
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...