I have a table where i store the date of player got enter in any game with the gameId and UserId
.
Now i have to calculate how much time since each user playing game.
Table schema is as following
create table GameUser
(
UserId int identity(1,1) not null,
UserName nvarchar(500)
)
insert into GameUser SELECT 'rahul'
insert into GameUser SELECT 'yunus'
insert into GameUser SELECT 'nitin'
Create table GameEntry
(
EntryId int identity(1,1) not null,
GameId int ,
UserId int ,
EntryDate smalldatetime
)
insert into GameEntry SELECT 1,1,'01/01/2009'
insert into GameEntry SELECT 1,2,'05/01/2009'
insert into GameEntry SELECT 1,3,'12/01/2009'
insert into GameEntry SELECT 2,1,'01/01/2010'
insert into GameEntry SELECT 2,3,'01/01/2013'
SQL FIDDELE with table scheme and test data
my result column for duration should be like this 2 years 2 months and 15 days
or 3 months
or 5 months 15 days
or 9 days
I already check age calculation questions on SO, but there are more complicated .