Question: I cannot get the time difference from a certain date using Powershell like below:

```
$Date = '11/12/2001'
(New-TimeSpan -Start (Get-Date -Date $Date) -End (Get-Date)).ToString("'yyyy' Years 'MM' Months 'dd' Days 'hh' Hours 'mm' Minutes 'ss' Seconds'")

```

Error:
------

```
Exception calling "ToString" with "1" argument(s): "Input string was not in a correct format." 
At line:2 char:1 
+ (New-TimeSpan -Start (Get-Date -Date $Date) -End (Get-Date)).ToString ... 

```

Why I cannot get the Years and Months elapsed?

Answer: 
You can use `row_number()`:

```
select t.*
from (select t.*,
             row_number() over (partition by name order by logindate) as seqnum
      from t
     ) t
where seqnum <= 2;

```

If all names have at least two rows, then this should be an efficient method:

```
select t.*
from t
where t.logindate <= (select t2.logindate
                      from t t2
                      where t2.name = t.name
                      limit 1 offset 1
                     );

```

This can be modified to handle singleton names, but that adds a little complication.
You can use a simple correlated sub query here

```
select *
    from table1 a
    where (
        select count(*)
        from table1
        where a.name = name
       and a.LoginDate > LoginDate
    ) < 2
order by a.name

```

[DEMO](http://sqlfiddle.com/#!9/9533bc/9)