Re: Fw: Date Add
| From: | John Fishworld | Date: | Sun, 04 Aug 2002 21:58:35 +0000 |
| Subject: | Re: Fw: Date Add | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-20990@lists.php.net to get a copy of this message | ||
sorry yes its mysql !
because I only want events now or in the future of the one month !
before the search clause I grab the time required
if ($month == date("m")) {
$tosearch = date("Y-$month-d 00:00:00");
$today = getdate();
$mday = $today['mday'];
$year = $today['year'];
$mday = sprintf ("%02s",$mday);
$aktdate = $mday . "." . $month . "." . $year;
# check for last day of month
$lday = 31;
while(!checkdate($month, $lday, $year)) {
$lday--;
}
// lastday in month
// so interval should be
$int = ($lday - $mday);
} else {
// max number of days
$int = 31;
$tosearch = date("Y-$month-01 00:00:00");
}
so that in my query
SELECT DISTINCT t_city_name,t_city_id_city FROM
t_city,t_zipcodecity,t_location,t_event WHERE (t_city_id_city =
t_zipcodecity_id_city) AND (t_zipcodecity_zipcode = t_location_zipcode )
AND
((t_location_sex = 4) OR (t_location_sex = 6) OR (t_location_sex = 0)) AND
(t_location_id_location = t_event_id_location) AND (t_event_date <
(DATE_ADD('$tosearch', INTERVAL 31 day)) ) AND (t_event_date >
'$tosearch') ORDER by t_city_name
the '$tosearch' varies and only shows result for the last whatever days of
the month
>
> Why not simply does the where clause like :
> for a whole month, here is july:
> WHERE YEAR(t_event_date)='2002' AND MONTH(t_event_date)='7'
>
> For a specific day, here the current day
> WHERE t_event_date=NOW()
>
> That means you store date as date/timestamp/... field type. You do not
specify your rdbm, but seems to be mysql ;).
>
> hth
>
> pa
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>