chicote 0 Posted May 26, 2020 Report Share Posted May 26, 2020 Olá, Como é que faço uma Query de forma a que me devolva resultados com menos de 24 horas? Ou seja, imaginem, tenho uma tabela com noticias, essa tabela tem uma coluna em que regista a hora de entrada através da função PHP time(). Quero apenas que me devolva resultados que tenham sido registados há menos de 24 horas. Alguém pode dar uma ajudinha? Obrigadão Link to post Share on other sites
M6 150 Posted May 26, 2020 Report Share Posted May 26, 2020 O time não serve. Tens de usar o datetime para saber a data. Sem saberes a data não sabes o tempo das últimas 24 horas. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
chicote 0 Posted May 26, 2020 Author Report Share Posted May 26, 2020 o time não serve? Mas o time gera um valor convertivel 1590509558 = Terça-feira, 26 de Maio de 2020 17:12:38 E como faria com o datetime? Obrigado. Link to post Share on other sites
chicote 0 Posted May 26, 2020 Author Report Share Posted May 26, 2020 Olhe como fiz.. Não se deixe rir 🙄 Tenho medo que seja arcaico e provoque algum erro. Mas funciona. $umDia = '86400'; $now = time(); $dif = $now-$umDia; $getMynew = $mysqli->query("SELECT * FROM news WHERE idUs = '{$data['user_id']}' AND time_creation < '$dif' "); Link to post Share on other sites
M6 150 Posted May 27, 2020 Report Share Posted May 27, 2020 Se tens uma data e uma hora não é time, é datetime. Podes obter as últimas 24 horas usando NOW() - INTERVAL 1 DAY. 1 Report 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now