Monday, March 19, 2012

date in a database

dear experst:

i have a web site and a calendar where a client can select a day week or a month to see some statistics, for the day i know how to do it. and i have also stored procedures. what i want is how to store the startday and end day in a variable when the client select a week or a month, so i can assign these variables to the stored procedure so the stored procedure can query the database and return the data for just the specific selected date.

this problem is realy annoying me and i can not continue my work without solving it. any help will be more than appreciated.
thanksvarname1 = startday
varname2 = endday|||thanks for your reply,
what i want is how to know the start date and the end date when i user select a week or a month and how to calculate the value so when give it to the stored procedure it will know that is a week?
thanks|||to get the Frist/Last day-of-the-week, Frist/Last day-of-the-month u can use the following queries. this assumes that Sunday is the first day of the week and Saturday is that last one. also the dates r calculated with respect to date variable.

declare @.DtVar smalldatetime
set @.DtVar = '2007-03-22' -- an example date
select @.DtVar+1-datepart(dw,@.DtVar) as StartingDayOfTheWeek
select @.DtVar+7-datepart(dw,@.DtVar) as LastDayOfTheWeek
select @.DtVar+1 - datepart(dd,@.DtVar) as FristDateOfTheMonth
select dateadd(mm,1,@.DtVar) - datepart(dd,@.DtVar) as LastDateOfTheMonth|||thanks a lot for your answer, but what if i want monday be the first day of the week and sunday the last day of the week? what should i changed.
thanks|||dude, please play around with the number. when you got a solution for a problem, you shall learn to understand it and explore further. By asking, "what if i want Monday", you're asking the same question...|||Set @.@.datefirst 1|||thanks a lot for your answer, but what if i want monday be the first day of the week and sunday the last day of the week? what should i changed.
thanks

You can assign the days into an int array and pass to your stored procedure.

No comments:

Post a Comment