Unix Technical Forum

pulling upcoming dates

This is a discussion on pulling upcoming dates within the MySQL forums, part of the Database Server Software category; --> On 31 Jan, 10:00, "Luuk" <l...@invalid.lan> wrote: > "Captain Paralytic" <paul_laut...@yahoo.com> schreef in berichtnews:9a68a4dd-07df-4e0d-89af-12c851ca9177@q21g2000hsa.googlegroups.com... > > > > > ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 02-28-2008, 10:32 AM
Captain Paralytic
 
Posts: n/a
Default Re: pulling upcoming dates

On 31 Jan, 10:00, "Luuk" <l...@invalid.lan> wrote:
> "Captain Paralytic" <paul_laut...@yahoo.com> schreef in berichtnews:9a68a4dd-07df-4e0d-89af-12c851ca9177@q21g2000hsa.googlegroups.com...
>
>
>
> > On 31 Jan, 09:01, "Luuk" <l...@invalid.lan> wrote:
> >> "Paul Lautman" <paul.laut...@btinternet.com> schreef in
> >> berichtnews:60bvnqF1msefuU1@mid.individual.net...

>
> >> > Carolyn Marenger wrote:
> >> >> How do I perform a select statement that would locate all records in
> >> >> which the day and month are in the next say 30 days regardless of the
> >> >> year. Basically an upcoming birthday/anniversary list.

>
> >> >> Thanks, Carolyn

>
> >> > I'm sure there's an easier way to do this, but here at least is one
> >> > method. Supposing the date field is anniversary:

>
> >> > SELECT
> >> > *
> >> > WHERE
> >> > DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(anniversary),'-',DAY(anniversary)),NOW())
> >> > < 30

>
> >> select datediff(now(),'2008-03-31');
> >> returns
> >> -60

>
> >> so,
> >> SELECT
> >> *
> >> WHERE
> >> ABS(DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(anniversary),'-',DAY(anniversary)),NOW())
> >> )
> >> < 30

>
> >> might work better...

>
> > Since the query has NOW() in the second position, your query with
> > NOW() in the first position cannot occur (parameters do not swap
> > positions all by themselves).

>
> ok, but
> select datediff('2007-12-01',now());
> also returns a negative number
>
> so by next month, when now is i.e. 2008-02-20
> this: select datediff('2008-01-01',now());
> will also return a negative number...


True, I KNEW you were on to something, I just realised that what you
had said was not it, but I didn't suss what it actually was.

So the where needs to be
WHERE
DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(anniversary),'-',DAY(anniversary)),NOW())
BETWEEN 0 AND 30

Thanks for that Luuk.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 02-28-2008, 10:32 AM
Carolyn Marenger
 
Posts: n/a
Default Re: pulling upcoming dates

Captain Paralytic wrote:
> On 31 Jan, 10:00, "Luuk" <l...@invalid.lan> wrote:
>> "Captain Paralytic" <paul_laut...@yahoo.com> schreef in berichtnews:9a68a4dd-07df-4e0d-89af-12c851ca9177@q21g2000hsa.googlegroups.com...
>>
>>
>>
>>> On 31 Jan, 09:01, "Luuk" <l...@invalid.lan> wrote:
>>>> "Paul Lautman" <paul.laut...@btinternet.com> schreef in
>>>> berichtnews:60bvnqF1msefuU1@mid.individual.net...
>>>>> Carolyn Marenger wrote:
>>>>>> How do I perform a select statement that would locate all records in
>>>>>> which the day and month are in the next say 30 days regardless of the
>>>>>> year. Basically an upcoming birthday/anniversary list.
>>>>>> Thanks, Carolyn
>>>>> I'm sure there's an easier way to do this, but here at least is one
>>>>> method. Supposing the date field is anniversary:
>>>>> SELECT
>>>>> *
>>>>> WHERE
>>>>> DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(anniversary),'-',DAY(anniversary)),NOW())
>>>>> < 30
>>>> select datediff(now(),'2008-03-31');
>>>> returns
>>>> -60
>>>> so,
>>>> SELECT
>>>> *
>>>> WHERE
>>>> ABS(DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(anniversary),'-',DAY(anniversary)),NOW())
>>>> )
>>>> < 30
>>>> might work better...
>>> Since the query has NOW() in the second position, your query with
>>> NOW() in the first position cannot occur (parameters do not swap
>>> positions all by themselves).

>> ok, but
>> select datediff('2007-12-01',now());
>> also returns a negative number
>>
>> so by next month, when now is i.e. 2008-02-20
>> this: select datediff('2008-01-01',now());
>> will also return a negative number...

>
> True, I KNEW you were on to something, I just realised that what you
> had said was not it, but I didn't suss what it actually was.
>
> So the where needs to be
> WHERE
> DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(anniversary),'-',DAY(anniversary)),NOW())
> BETWEEN 0 AND 30
>
> Thanks for that Luuk.


Thanks to you and Luuk for your assistance with this. It works, now I
just have to write the PHP application to use the query.

Carolyn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 02-28-2008, 10:32 AM
Carolyn Marenger
 
Posts: n/a
Default SOLVED - pulling upcoming dates

Carolyn Marenger wrote:
> How do I perform a select statement that would locate all records in
> which the day and month are in the next say 30 days regardless of the
> year. Basically an upcoming birthday/anniversary list.
>
> Thanks, Carolyn


The following command worked for me. Thanks to Luuk and Captain
Paralytic for their debate in developing it.

SELECT description, eventDate
FROM dates
WHERE
DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(eventDate),'-',DAY(eventDate)),NOW())
BETWEEN 0 AND 60
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 02-28-2008, 10:32 AM
Rik Wasmus
 
Posts: n/a
Default Re: SOLVED - pulling upcoming dates

On Thu, 31 Jan 2008 12:21:14 +0100, Carolyn Marenger <cajunk@marenger.com>
wrote:

> Carolyn Marenger wrote:
>> How do I perform a select statement that would locate all records in
>> which the day and month are in the next say 30 days regardless of the
>> year. Basically an upcoming birthday/anniversary list.
>> Thanks, Carolyn

>
> The following command worked for me. Thanks to Luuk and Captain
> Paralytic for their debate in developing it.
>
> SELECT description, eventDate
> FROM dates
> WHERE
> DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(eventDate),'-',DAY(eventDate)),NOW())
> BETWEEN 0 AND 60


Let's say today is 2007-12-05, date to check is 1982-01-16...

mysql> select
DATEDIFF(CONCAT(YEAR('2007-12-05'),'-',MONTH('1982-01-16'),'-',DAY('1982-01-16')),'2007-12-05');

+--------+
| -323 |
+--------+


SELECT
description,
eventDate,
DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(eventDate),'-',DAY(eventDate)),NOW())
as checkdays.
FROM dates
HAVING checkdays BETWEEN 0 AND 60
OR checkdays BETWEEN -365 AND (-365 + 60)

Now all we need is a statement to check for a leap year....
--
Rik Wasmus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 02-28-2008, 10:32 AM
Carolyn Marenger
 
Posts: n/a
Default Re: SOLVED - pulling upcoming dates

Rik Wasmus wrote:
> On Thu, 31 Jan 2008 12:21:14 +0100, Carolyn Marenger
> <cajunk@marenger.com> wrote:
>
>> Carolyn Marenger wrote:
>>> How do I perform a select statement that would locate all records in
>>> which the day and month are in the next say 30 days regardless of the
>>> year. Basically an upcoming birthday/anniversary list.
>>> Thanks, Carolyn

>>
>> The following command worked for me. Thanks to Luuk and Captain
>> Paralytic for their debate in developing it.
>>
>> SELECT description, eventDate
>> FROM dates
>> WHERE
>> DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(eventDate),'-',DAY(eventDate)),NOW())
>> BETWEEN 0 AND 60

>
> Let's say today is 2007-12-05, date to check is 1982-01-16...
>
> mysql> select
> DATEDIFF(CONCAT(YEAR('2007-12-05'),'-',MONTH('1982-01-16'),'-',DAY('1982-01-16')),'2007-12-05');
>
>
> +--------+
> | -323 |
> +--------+
>
>
> SELECT
> description,
> eventDate,
> DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(eventDate),'-',DAY(eventDate)),NOW())
> as checkdays.
> FROM dates
> HAVING checkdays BETWEEN 0 AND 60
> OR checkdays BETWEEN -365 AND (-365 + 60)
>
> Now all we need is a statement to check for a leap year....


Good point. Thanks!

Carolyn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 02-28-2008, 10:32 AM
Luuk
 
Posts: n/a
Default Re: SOLVED - pulling upcoming dates


"Carolyn Marenger" <cajunk@marenger.com> schreef in bericht
news:77014$47a1adcc$cf70133e$440@PRIMUS.CA...
> Carolyn Marenger wrote:
>> How do I perform a select statement that would locate all records in
>> which the day and month are in the next say 30 days regardless of the
>> year. Basically an upcoming birthday/anniversary list.
>>
>> Thanks, Carolyn

>
> The following command worked for me. Thanks to Luuk and Captain Paralytic
> for their debate in developing it.
>
> SELECT description, eventDate
> FROM dates
> WHERE
> DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(eventDate),'-',DAY(eventDate)),NOW())
> BETWEEN 0 AND 60


one day, it wil be i.e 1st december, and someone has his/her birtday on i.e.
1st january

your statement fives (with dates filled in):
SELECT description, eventDate
FROM dates
WHERE
DATEDIFF(CONCAT('2008-01-01'), '2008-12-01')
BETWEEN 0 AND 60

so, will not select this person..




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 02-28-2008, 10:32 AM
Luuk
 
Posts: n/a
Default Re: SOLVED - pulling upcoming dates


"Luuk" <luuk@invalid.lan> schreef in bericht
news:7rs875-ifb.ln1@leafnode.a62-251-88-195.adsl.xs4all.nl...
>
> "Carolyn Marenger" <cajunk@marenger.com> schreef in bericht
> news:77014$47a1adcc$cf70133e$440@PRIMUS.CA...
>> Carolyn Marenger wrote:
>>> How do I perform a select statement that would locate all records in
>>> which the day and month are in the next say 30 days regardless of the
>>> year. Basically an upcoming birthday/anniversary list.
>>>
>>> Thanks, Carolyn

>>
>> The following command worked for me. Thanks to Luuk and Captain
>> Paralytic for their debate in developing it.
>>
>> SELECT description, eventDate
>> FROM dates
>> WHERE
>> DATEDIFF(CONCAT(YEAR(NOW()),'-',MONTH(eventDate),'-',DAY(eventDate)),NOW())
>> BETWEEN 0 AND 60

>
> one day, it wil be i.e 1st december, and someone has his/her birtday on
> i.e. 1st january
>
> your statement fives (with dates filled in):
> SELECT description, eventDate
> FROM dates
> WHERE
> DATEDIFF(CONCAT('2008-01-01'), '2008-12-01')
> BETWEEN 0 AND 60
>
> so, will not select this person..
>
>
>
>


thanks Rik, you where quicker... ;-)


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:19 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com