Bluehost.com Web Hosting $6.95

find a date range between current date and 1 year ago

This is a discussion on find a date range between current date and 1 year ago within the MySQL Database forums, part of the Database Forums category; hey i need to find a date range between the current date and the date one year ago based on ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-22-2007
Lord Kelvan
 
Posts: n/a
Default find a date range between current date and 1 year ago

hey i need to find a date range between the current date and the date
one year ago based on the current date

so far i have this sql code

SELECT type, SUM(quantity), date FROM table
WHERE date BETWEEN current_date() and ???????????????????????????
GROUP BY date, type
ORDER BY date;

i just need to know what i put in the ??????????????????????????? area

Regards
Kelvan

Reply With Quote
  #2 (permalink)  
Old 05-22-2007
J.O. Aho
 
Posts: n/a
Default Re: find a date range between current date and 1 year ago

Lord Kelvan wrote:
> hey i need to find a date range between the current date and the date
> one year ago based on the current date
>
> so far i have this sql code
>
> SELECT type, SUM(quantity), date FROM table
> WHERE date BETWEEN current_date() and ???????????????????????????
> GROUP BY date, type
> ORDER BY date;
>
> i just need to know what i put in the ??????????????????????????? area


One of the following should do what you need:

PERIOD_ADD(P,N)
ADDDATE(date,INTERVAL expr unit)
ADDDATE(expr,days)

http://dev.mysql.com/doc/refman/5.0/...ion_period-add

--

//Aho
Reply With Quote
  #3 (permalink)  
Old 05-22-2007
Lord Kelvan
 
Posts: n/a
Default Re: find a date range between current date and 1 year ago

On May 22, 4:19 pm, "J.O. Aho" <u...@example.net> wrote:
> One of the following should do what you need:
>
> PERIOD_ADD(P,N)
> ADDDATE(date,INTERVAL expr unit)
> ADDDATE(expr,days)
>
> http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...
>
> --
>
> //Aho


thoes functions are good but they are for future dates not prior dates
i have the current date and basically i need a dynamic sql script to
take todays date and count back 1 year and get that date

regards
Kelvan

Reply With Quote
  #4 (permalink)  
Old 05-22-2007
J.O. Aho
 
Posts: n/a
Default Re: find a date range between current date and 1 year ago

Lord Kelvan wrote:
> On May 22, 4:19 pm, "J.O. Aho" <u...@example.net> wrote:
>> One of the following should do what you need:
>>
>> PERIOD_ADD(P,N)
>> ADDDATE(date,INTERVAL expr unit)
>> ADDDATE(expr,days)
>>
>> http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...


> thoes functions are good but they are for future dates not prior dates
> i have the current date and basically i need a dynamic sql script to
> take todays date and count back 1 year and get that date


mysql> select ADDDATE(CURRENT_DATE(),INTERVAL -31 DAY);
+------------------------------------------+
| ADDDATE(CURRENT_DATE(),INTERVAL -31 DAY) |
+------------------------------------------+
| 2007-04-21 |
+------------------------------------------+
1 row in set (0.00 sec)

--

//Aho
Reply With Quote
  #5 (permalink)  
Old 05-22-2007
Captain Paralytic
 
Posts: n/a
Default Re: find a date range between current date and 1 year ago

On 22 May, 05:41, Lord Kelvan <the_idd...@hotmail.com> wrote:
> On May 22, 4:19 pm, "J.O. Aho" <u...@example.net> wrote:
>
> > One of the following should do what you need:

>
> > PERIOD_ADD(P,N)
> > ADDDATE(date,INTERVAL expr unit)
> > ADDDATE(expr,days)

>
> >http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...

>
> > --

>
> > //Aho

>
> thoes functions are good but they are for future dates not prior dates
> i have the current date and basically i need a dynamic sql script to
> take todays date and count back 1 year and get that date
>
> regards
> Kelvan


so try DATE_SUB

Reply With Quote
  #6 (permalink)  
Old 05-23-2007
Lord Kelvan
 
Posts: n/a
Default Re: find a date range between current date and 1 year ago

On May 22, 8:30 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 22 May, 05:41, Lord Kelvan <the_idd...@hotmail.com> wrote:
>
>
>
>
>
> > On May 22, 4:19 pm, "J.O. Aho" <u...@example.net> wrote:

>
> > > One of the following should do what you need:

>
> > > PERIOD_ADD(P,N)
> > > ADDDATE(date,INTERVAL expr unit)
> > > ADDDATE(expr,days)

>
> > >http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...

>
> > > --

>
> > > //Aho

>
> > thoes functions are good but they are for future dates not prior dates
> > i have the current date and basically i need a dynamic sql script to
> > take todays date and count back 1 year and get that date

>
> > regards
> > Kelvan

>
> so try DATE_SUB- Hide quoted text -
>
> - Show quoted text -


date sub wont work it is for subtracting dates but i realised one
night when i was trying to sleep that you should be able to use
negative numbers in the functions thank you for your help

Reply With Quote
  #7 (permalink)  
Old 05-24-2007
Captain Paralytic
 
Posts: n/a
Default Re: find a date range between current date and 1 year ago

On 23 May, 22:15, Lord Kelvan <the_idd...@hotmail.com> wrote:
> On May 22, 8:30 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
> > On 22 May, 05:41, Lord Kelvan <the_idd...@hotmail.com> wrote:

>
> > > On May 22, 4:19 pm, "J.O. Aho" <u...@example.net> wrote:

>
> > > > One of the following should do what you need:

>
> > > > PERIOD_ADD(P,N)
> > > > ADDDATE(date,INTERVAL expr unit)
> > > > ADDDATE(expr,days)

>
> > > >http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...

>
> > > > --

>
> > > > //Aho

>
> > > thoes functions are good but they are for future dates not prior dates
> > > i have the current date and basically i need a dynamic sql script to
> > > take todays date and count back 1 year and get that date

>
> > > regards
> > > Kelvan

>
> > so try DATE_SUB- Hide quoted text -

>
> > - Show quoted text -

>
> date sub wont work it is for subtracting dates but i realised one
> night when i was trying to sleep that you should be able to use
> negative numbers in the functions thank you for your help- Hide quoted text -
>
> - Show quoted text -


DATE_SUB will work as it will return a date in the past for you to use
in a compare!

Reply With Quote
  #8 (permalink)  
Old 05-25-2007
Lord Kelvan
 
Posts: n/a
Default Re: find a date range between current date and 1 year ago

yes and thats good but i want it to be dynamic so i dont have to touch
it periodadd with a negtive number will be good thx for ppls help

Reply With Quote
  #9 (permalink)  
Old 05-25-2007
Captain Paralytic
 
Posts: n/a
Default Re: find a date range between current date and 1 year ago

On 24 May, 23:07, Lord Kelvan <the_idd...@hotmail.com> wrote:
> yes and thats good but i want it to be dynamic so i dont have to touch
> it periodadd with a negtive number will be good thx for ppls help


DATE_SUB with a positive number is the equivalent of ADDDATE with a
negative number.

Both are as dynamic as each other.

PERIOD_ADD however does not return a date.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:11 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0