1
I created the query so that when a plan expires, the output 'Date' will print 'Expired' and if it has not yet expired, print 'Current', but I need to take into account also the time(s), minute(s) and second(s) of the expiration date, because it should match the date of registration of the client’s plan in the database.
What is happening is that if the date is equal to 'today', but it has not yet fully expired taking into account the time(s), minute(s) and second(s), the return is 'Expired' in the same way, and it could not be so.
What I’ve done as far as I can, if the expiration date is longer than NOW(), is working as far as I know from the tests I’ve done:
$sql_plano = "SELECT
*,
(
SELECT
`nome`
FROM
`plano_pacote`
WHERE
`token` = `ps_token`
LIMIT
1
) AS `plano_nome`,
(
SELECT
CASE
WHEN DATEDIFF(`data_expira`, NOW()) < 0 THEN 'Expirado'
ELSE
'Vigente'
END) AS `Data`
FROM
`plano_usuario`
WHERE
`user_token` = '%s'
AND
`status` = 'A'
ORDER BY
`data_cad`
DESC
LIMIT
1
;";
The field data_expira
is the type DATETIME
, and registration is for '2019-05-10 23:51:37'
But DATEDIFF is not for hours and minutes. If it is to consider have to use TIMEDIFF. This sort of thing usually resolves with a careful reading of the manual.
– Bacco
Reverti your edit, if you want to post the solution, use the bottom field, answers, and mark as accepted later.
– Bacco
@Bacco hi, thanks, I was editing the question when you guided me, I found the references on the mysql site and I will study more, I’m now starting to delve into sql, thanks beast.
– ElvisP
Okay, look at the history at https://answall.com/posts/383064/revisions. to copy your solution and paste it into the appropriate field (the solution goes below, in the answers, and not in the body of the question)
– Bacco
Thanks for the tip✨
– ElvisP