chicote Posted May 26, 2020 at 01:39 PM Report #618216 Posted May 26, 2020 at 01:39 PM 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
M6 Posted May 26, 2020 at 03:50 PM Report #618218 Posted May 26, 2020 at 03:50 PM 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."
chicote Posted May 26, 2020 at 04:15 PM Author Report #618219 Posted May 26, 2020 at 04:15 PM 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.
chicote Posted May 26, 2020 at 04:38 PM Author Report #618220 Posted May 26, 2020 at 04:38 PM 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' ");
M6 Posted May 27, 2020 at 10:10 AM Report #618228 Posted May 27, 2020 at 10:10 AM 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."
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