SELECT date query
am 07.10.2006 05:29:35 von Ron Piggott
--=-L+W1mjMoEL0y5d7046uZ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
I am wondering if someone would help me write a SELECT date query ...
Weekly mailings go out every Wednesday. I am setting up an
administration function and table to store the mailing name, PDF to be
contained within the mailing and the date for it to be used.
The SELECT query I want to create is for the next 12 records which are
going to be used to be displayed. The first record would be next
Wednesday (not October 11th, but calendar wise based on when the script
ran) and then the following 11 Wednesdays.
SELECT * FROM christian_discipleship WHERE created_for_date =
'$next_wednesday' ORDER BY created_for_date ASC LIMIT 12
I am not sure how to generate the value for $next_wednesday
Any ideas?
Ron
--=-L+W1mjMoEL0y5d7046uZ--
Re: SELECT date query
am 07.10.2006 06:49:36 von Niel Archer
Hi Ron
I've made the assumption that if today is Wednesday, you still want next
Wednesday.
Try this:
$offset = array(3,2,1,7,6,5,4);
$date = explode("-", date("Y-n-j"));
$ToDay = DayOfWeek($date[0], $date[1], $date[2]);
$NextWed = date("Y-n-j", time() + ($offset[$ToDay] * 24 * 60 * 60));
// Returns a digit in range 0-6. 0 = Sunday, 6 = Saturday
function DayOfWeek($Year, $Month, $Day)
{
$t = array(0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4);
$Year -= $Month < 3;
return ($Year + ($Year / 4) - ($Year / 100) + ($Year / 400) +
$t[$Month - 1] + $Day) % 7;
}
Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SELECT date query
am 07.10.2006 10:28:18 von Hodicska Gergely
Hi!
You can make this easier with date('w').
$correction = array(3, 2, 1, 7, 6, 5, 4);
list($year, $month, $day, $dayOfWeek) = explode('|', date('Y|m|d|w'));
echo date ("Y.m.d", mktime
(0,0,0,$month,$day+$correction[$dayOfWeek],$year));
Regards,
FelhÅ
Niel Archer wrote:
> Hi Ron
>
> I've made the assumption that if today is Wednesday, you still want next
> Wednesday.
> Try this:
>
> $offset = array(3,2,1,7,6,5,4);
> $date = explode("-", date("Y-n-j"));
> $ToDay = DayOfWeek($date[0], $date[1], $date[2]);
> $NextWed = date("Y-n-j", time() + ($offset[$ToDay] * 24 * 60 * 60));
>
> // Returns a digit in range 0-6. 0 = Sunday, 6 = Saturday
> function DayOfWeek($Year, $Month, $Day)
> {
> $t = array(0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4);
> $Year -= $Month < 3;
> return ($Year + ($Year / 4) - ($Year / 100) + ($Year / 400) +
> $t[$Month - 1] + $Day) % 7;
> }
>
>
> Niel
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SELECT date query
am 07.10.2006 18:26:20 von Niel Archer
Hi
> You can make this easier with date('w').
Doh, that'll teach me to code at 5 am. I knew there was a better way,
but couldn't think of it, the sound of my bed calling was too
distracting.
Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SELECT date query
am 08.10.2006 17:26:24 von Bastien Koert
i tend to take the approach of
$next_wed = date("Y-m-d", strtotime("next wednesday"));
Bastien
>From: Niel Archer
>Reply-To: php-db@lists.php.net
>To: php-db@lists.php.net
>Subject: Re: [PHP-DB] SELECT date query
>Date: Sat, 07 Oct 2006 05:49:36 +0100
>
>Hi Ron
>
>I've made the assumption that if today is Wednesday, you still want next
>Wednesday.
>Try this:
>
>$offset = array(3,2,1,7,6,5,4);
>$date = explode("-", date("Y-n-j"));
>$ToDay = DayOfWeek($date[0], $date[1], $date[2]);
>$NextWed = date("Y-n-j", time() + ($offset[$ToDay] * 24 * 60 * 60));
>
>// Returns a digit in range 0-6. 0 = Sunday, 6 = Saturday
>function DayOfWeek($Year, $Month, $Day)
>{
> $t = array(0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4);
> $Year -= $Month < 3;
> return ($Year + ($Year / 4) - ($Year / 100) + ($Year / 400) +
>$t[$Month - 1] + $Day) % 7;
>}
>
>
>Niel
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php