Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Select filtering by date


Message #1 by "Marcelo" <foros@f...> on Wed, 19 Sep 2001 19:31:48 -0300
Hi everyone, I  need to select some data from my DB filtering by date...but

selecting only taht records which have the REG_VENC field (DATE / TIME as

19/09/2001 12:45:15) that contains a date of no more than 7 week before.

Understand?  is to get all the data for this week.



I did this to select the same, but for the whole month beginnning from

today.



SELECT * FROM registros WHERE (YEAR(reg_venc) = 2001 AND MONTH(reg_venc) = 9

AND day(reg_venc) >= 19) ORDER BY reg_venc



I think that maybe exists a simply solution....yeah?  this is preety like an

amateur sql user do (me :-)  )



Can you help me with thw correct way to do this?  (and the same for Time

instead of dates)



Thanks!!



Marcelo



Message #2 by "phil griffiths" <pgtips@m...> on Thu, 20 Sep 2001 09:21:02
take a look at the T-SQL datediff function.  You don't say what db you 

use, but if its SQL server you can do something like

SELECT * FROM registros WHERE DATEDIFF(day, reg_venc, getdate()) < 7



For times just change the day parameter to whatever you want: hour, 

minute, second, millisecond.



Phil

> Hi everyone, I  need to select some data from my DB filtering by 

date...but

> selecting only taht records which have the REG_VENC field (DATE / TIME as

> 19/09/2001 12:45:15) that contains a date of no more than 7 week before.

> Understand?  is to get all the data for this week.

> 

> I did this to select the same, but for the whole month beginnning from

> today.

> 

> SELECT * FROM registros WHERE (YEAR(reg_venc) = 2001 AND MONTH(reg_venc) 

= 9

> AND day(reg_venc) >= 19) ORDER BY reg_venc

> 

> I think that maybe exists a simply solution....yeah?  this is preety 

like an

> amateur sql user do (me :-)  )

> 

> Can you help me with thw correct way to do this?  (and the same for Time

> instead of dates)

> 

> Thanks!!

> 

> Marcelo

> 

Message #3 by "Drew, Ron" <RDrew@B...> on Thu, 20 Sep 2001 07:58:07 -0400
SQL Server

SELECT * FROM registros WHERE DATEDIFF(DAY, reg_venc, getdate()) < 7 ORDER

by reg_venc



I believe in Access it would be

SELECT * FROM registros WHERE reg_venc BETWEEN (DATE()-7) AND DATE() ORDER

by reg_venc



-----Original Message-----

From: Marcelo [mailto:foros@f...]

Sent: Wednesday, September 19, 2001 6:32 PM

To: ASP Web HowTo

Subject: [asp_web_howto] Select filtering by date





Hi everyone, I  need to select some data from my DB filtering by date...but

selecting only taht records which have the REG_VENC field (DATE / TIME as

19/09/2001 12:45:15) that contains a date of no more than 7 week before.

Understand?  is to get all the data for this week.



I did this to select the same, but for the whole month beginnning from

today.



SELECT * FROM registros WHERE (YEAR(reg_venc) = 2001 AND MONTH(reg_venc) = 9

AND day(reg_venc) >= 19) ORDER BY reg_venc



I think that maybe exists a simply solution....yeah?  this is preety like an

amateur sql user do (me :-)  )



Can you help me with thw correct way to do this?  (and the same for Time

instead of dates)



Thanks!!



Marcelo








  Return to Index