Link to home
Start Free TrialLog in
Avatar of evibesmusic
evibesmusicFlag for United States of America

asked on

How to compare DateTime between two Unix Timestamps in MySQL?

Experts,

Not sure why I am stumbling here so much but, I need to compare a DateTime field within my database to see if the dates stored in this column are between two user submitted Unix Timestamps.

Example (not working): SELECT * FROM registration WHERE checkin BETWEEN FROM_UNIXTIME('".$_POST['from']."') AND FROM_UNIXTIME('".$_POST['to']."') AND `appointment`=1 AND `deleted` IS NULL ORDER BY checkin ASC;

When attempting to validate by printing my query to the screen, I get the following which seems correct: SELECT * FROM registration WHERE checkin BETWEEN FROM_UNIXTIME('1571011200000') AND FROM_UNIXTIME('1571616000000') AND `appointment`=1 AND `deleted` IS NULL ORDER BY checkin ASC;

I'm not receiving any syntax errors but, not sure I am employing the "FROM UNIXTIME()" function properly???

Cheers!
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of evibesmusic

ASKER

@noci,

That seemed to do it. Interestingly enough, I'm employing HTML5 date selector inputs and the format you see my timestamps in is the format the date selector posts the data. I appreciate your help.

Cheers!
Thank you @noci.