English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
0

How can I get information which occured on specific days of interval. For example all users who subscribed last week[FROM MONDAY TO SUNDAY]only.
Thanks in advance

2006-08-23 10:14:54 · 5 answers · asked by Teddy 1 in Computers & Internet Programming & Design

I want to write a query that can return all user information from the database that has been added into my database in the last week for example.
Thanks again

2006-08-23 10:22:18 · update #1

5 answers

Here's your answer for MS T-SQL:


--you'll need some variables
declare @pWkStart as smalldatetime
declare @pWkEnd as smalldatetime
declare @pWeekdayGetdate as varchar (30)
declare @pDayOffset as integer


--determine today's weekday
select @pWeekdayGetdate = datename(weekday, getdate())

--based on today's weekday, calculate the beginning of the previous full week beginning on a monday
select @pDayOffset =

case
when @pWeekdayGetdate = 'monday'
then 7
when @pWeekdayGetdate = 'tuesday'
then 8
when @pWeekdayGetdate = 'wednesday'
then 9
when @pWeekdayGetdate = 'thursday'
then 10
when @pWeekdayGetdate = 'friday'
then 11
when @pWeekdayGetdate = 'saturday'
then 12
when @pWeekdayGetdate = 'sunday'
then 13
end

--subtract the offset from today's date to establish the beginning of the period
select @pWkStart = DATEADD ( day , -@pDayOffset , getdate() )

--add six more days to bring it to sunday
select @pWkEnd = DATEADD ( day , 6 , @pWkStart )


--use it in a SELECT statement
select * from MyTable Where MyField between @pWkStart and @pWkEnd

2006-08-30 16:49:05 · answer #1 · answered by © 2007. Sammy Z. 6 · 0 1

Let's say the table that contains your user info is called USERS and the subscribed date is in a field called SUBSCRIBED and the dates are 08/21/06 through 08/27/06.

Select *
From USERS
Where SUBSCRIBED between '08/21/06' and '08/27/06'

2006-08-23 11:22:30 · answer #2 · answered by MiggetyMiggetyMike 2 · 0 0

what you need to do is:

1. add the date to your db when someone join the list

2. when running the query have (in pseudo code):

SELECT * FROM table WHERE date > %today - 7 days

Check your favourite SQL website to learn the exact syntax

2006-08-23 11:24:27 · answer #3 · answered by le_gber 3 · 0 0

I can help you out on this sql thing bit be specific what is the programming php? if it any discussion board then perhaps they might able to help you out better

2006-08-23 10:18:16 · answer #4 · answered by Anonymous · 0 0

You can do using if condition with sysday function in SQL.

2006-08-31 01:40:45 · answer #5 · answered by Shamim P 1 · 0 0

fedest.com, questions and answers