Good afternoon, I need your help. My problem is the following, I need to extract data from a table which has two fields called "valid-until" (date type) and a "valid-until-time" (time type), so I need to extract the data when the current datetime is greater than those two fields, I tried to try this:
SELECT *
FROM `promocion`
WHERE ('2019-09-26'AND '19:00:00') >= ( `valido_hasta`AND `valido_hasta_time`)
but I did not get results I have searched the web but I do not find anything that helps me I would greatly appreciate your help
You need:
DATETIME
that would have the current date and timeCONCAT()
to match both :valido-hasta
andvalido-hasta-time
, leaving a blank space between the date and time.For you to go from having a date like this:
And an hour like this:
At the end you get a combined column in this format:
NOW()
that returns a result of typeDATETIME
So that inside the comparison looked something like this:
Your query could look like this:
You can occupy:
NOW()
CURRENT_TIMESTAMP()
The : function
CURDATE()
gives you the current date and the : functioncurTime()
gives you the current time.