searching the datas according to the date, month and year.

Posted by Gokul under Regular Expressions on 12/19/2010 | Points: 10 | Views : 1583 | Status : [Member] | Replies : 2
Dear Friends
I want to save the datas of the seller and the buyer details in DB with the date details . In order to search how many products have been soled in the particular day or month or year , how to search the datas which lies between the following period of date.

Thanks and Regards,
GokulNath Nithy.



Responses

Posted by: T.saravanan on: 12/20/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi GouklNath.N,

Just use the following query in your DB....

Get Date wise...
Select * from table where datepart(dd,DateColumnName) =25 order by DateColumnName desc


Get Month wise...
Select * from table where datepart(MM,DateColumnName) =10 order by DateColumnName desc


Get Year wise...
Select * from table where datepart(YYYY,DateColumnName) =2009 order by DateColumnName desc


Get Data between the date.....
Select * from table where DateColumnName between starting Date and Ending Date  order by DateColumnName desc


Try this way....

Cheers :)


Thanks,
T.Saravanan

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/8/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Try these samples

SELECT DATEDIFF(m, "24 March 2001","24 March 1964")
SELECT DATEDIFF(yyyy, "24 March 2001","24 March 1964")
SELECT DATEDIFF(mi, "24 March 2001","24 March 1964")
SELECT DATEDIFF(wk, "24 March 2001","24 March 1964")

DATEDIFF (Transact-SQL)
DATEDIFF ( datepart , startdate , enddate )
You can use SQL Server DateDiff function to calculate difference between two dates. This delay can be calculated in days, months, years, minutes,hours or seconds.

Here is documentation from MSDN window.google_render_ad();

datepart

Is the parameter that specifies on which part of the date to calculate the difference. The following table lists dateparts and abbreviations recognized by SQL Server 2005. These dateparts and abbreviations cannot be supplied as a user-declared variable.







Thanks
Karthik
www.f5Debug.net

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response