Get rows where lastLoginTimestamp is in last 7 days I'm trying to get the rows from a table where lastLoginTimestamp is in last 7 days and I'm doing as follow:

SELECT * FROM representative WHERE DATE_SUB(lastLoginTimestamp, INTERVAL 7 DAY)


lastLoginTimestamp is stored as a VARCHAR so this is where the problem is I though. How do get that rows in this case? Any help?

This are some of the values on that column to play with:

1427162434
1422557283
1395854997


Update

Based on the first answer I've changed my query to this:

SELECT
    *, from_unixtime(lastLoginTimestamp) AS lastLogin
FROM
    representative
WHERE
    DATE_SUB(
        from_unixtime(lastLoginTimestamp),
        INTERVAL 7 DAY
    )


But I'm getting the wrong values, for example I'm getting a row from this lastLogin = 2015-03-23 21:30:34 which is wrong
The values seem to be Unix timestamps, stored as strings. You can use the special datetime functions that MySQL has for conversions:

SELECT * 
FROM representative 
WHERE DATE_ADD(FROM_UNIXTIME(lastLoginTimestamp), INTERVAL 7 DAY) &gt;= NOW() ;


but it won't be very good for efficiency. Much more efficient, if there is an index on the column, to do it the other way around:  

(we assume that the values in the columns are CHAR(10). If some values have smaller length, you'll get erroneous results.)

SELECT * 
FROM representative 
WHERE lastLoginTimestamp 
      &gt;= CAST(UNIX_TIMESTAMP(NOW() - INTERVAL 7 DAY) AS CHAR(10));


The above condition if you want all rows, starting from exactly 7 days ago, same time as now. If you want rows starting from 6 days ago at midnight, so previous 6 days + today (whatever that is, a few minutes or 23 hours, 59 mins):

SELECT * 
FROM representative 
WHERE lastLoginTimestamp 
      &gt;= CAST(UNIX_TIMESTAMP(CURRENT_DATE - INTERVAL 6 DAY) AS CHAR(10));