Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to find data for previous week 2

Status
Not open for further replies.

gradinumcp

IS-IT--Management
Apr 6, 2005
85
US
Hi there...

I am trying to get a query that can find if a Loandate falls in last week...so basically check if loandate is between sunday or monday of last to friday or saturday of lastweek...

Any clues:

Select * from loan where last weeks sunday<Loandate>last week's saturday.

Thanks:)
 
I start by setting a couple of variables for start and end days, then run the select using these:
SELECT @startday:=if(dayofweek(curdate())=1,@startday:=(1+6),@startday:=(dayofweek(curdate()))+6),@start:= date_sub(curdate(), interval @startday day);

SELECT @endday:=if(dayofweek(curdate())=1,@endday:=1,@endday:=dayofweek(curdate())),@end:=date_sub(curdate(), interval @endday day);

SELECT *
FROM loan
WHERE
loandate >= @start
AND loandate <= @end;





______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hi

KarveR's solution is the nice and fast one, but for small amount of data I prefer a shorter way :
Code:
[b]select[/b] * [b]from[/b] loan [b]where[/b] date_format(loandate,[i]'%X %U'[/i])=date_format(current_date()-interval 7 day,[i]'%X %U'[/i]);

Feherke.
 
See now, when i asked that ages ago, no-one could answer it so I ended up with my (no rather clunky looking) solution.

I always figured thare had to be a more sophisticated method but never found it.

A star awarded to you sir!.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top