简体   繁体   中英

Get all rows with specific time difference

Hello i have a table like this:

|user_name|pw|register_date|last_time_entered

I want to get all the rows where last_seen_date - register_date < 7

I dont know how to write this query i thought about something like this

SELECT * FROM workoutlog_1.personal 
WHERE DATEDIFF(day, workoutlog_1.personal.register_date, workoutlog_1.personal.last_time_entered) < 7;

But i get this error:

Error Code: 1582. Incorrect parameter count in the call to native function 'DATEDIFF'

Thanks for helping.

Your error code seems to come from mysql.

With mysql, datediff takes only 2 parameters ( day is not needed)

I think that in (really) old versions, it took 3 parameters, now it works only with 2, and it will return days.

If you had to work with another unit (hour for example), you could use TIMESTAMPDIFF

MySql's DATEDIFF differs from SqlServers DATEDIFF in that it takes only 2 date parameters, and returns the difference in days. Since you want days anyway, just remove the day parameter, ie

SELECT * FROM workoutlog_1.personal 
WHERE DATEDIFF(workoutlog_1.personal.register_date, 
               workoutlog_1.personal.last_time_entered) < 7;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM