find difference in month and year in sql server 2005
Author:lisa PostAt:Wed, 26 Nov 2008 09:33:04 GMT Posted In:DataControls
Q:
--find day,month,year
--for day select datediff(d,'01 may 2008',getdate())
-- --for month select datediff(m,'01 jun 2006',getdate())
-- --for year select datediff(year,'01 jun 2006',getdate())
above working fine but suppose difference is 1 year 4 month and 2 month 15 days then It's giving 1 year and 2 month respectively.
but I want completely so I can use this in case of expired user in my project.
User can be expired in 1 month,3 month and 1 year. So I'm not able to recognize.
thanks
A:
convert a year into months and then find out the differences.
I hope this will work.
A:
It's not static that it's in month or days or years
so I cant do like this
thanks
A:
I guess that your tablestructure qould be like this, create table packages( PackageID int identity(1,1), PackagePeriod int)insert into packages values (10)insert into packages values (15)insert into packages values (20)create table packageusers( UserId int identity(1,1), PackageId int, JoinedDate datetime default getdate())insert into packageusers (PackageId) values (1)insert into packageusers (PackageId) values (2)insert into packageusers (PackageId) values (3)Users who are going to expire in next @n daysselect * from packageusers puinner join packages p on pu.packageid = p.packageidwhere dateadd(d,PackagePeriod,joineddate) <= dateadd(d,@n,joineddate)
Previous: index table1 and select for 647.600 records.. it is so slow.. but i have no index :)???
hello friendsi have table1 and 200 coulumn of table1 :) i have 647.600 records. i entered my records to table1 with for step to code lines in one day :)i select category1 category2 and category3 with select code but i have just one index.. it is productnumber and it is primarykey..So my... more
Next: NoneRandom Recommend
- SQL Server preparation Sites.
- ObjectDataSource.Updating vs Gridview.ItemUpdating?
- SelectedValue from a comboBox
- ObjectDataSource 'ObjectDataSource1' could not find a non-generic method
- SQL Old school *= Question select All rows from table A and rows from B
- How to use like operator?
- Index Out of range?!?
- LINQ - xPath - xQuery
- Unable to update Database
- Select STMT to Combine STRING and INT
Rss Feed