Check current date automatically

Asked

Viewed 207 times

2

I’m developing a system in PHP where: I make available an entry contest page for the staff, but this page has an end time, example: The page will be available from today 08/05/18 :17:11 and will disappear on 09/05/18 23:59:00. I know I can capture the current date and time on mysql using the following select: SELECT DATE_FORMAT(NOW(), '%d/%m/%Y %H:%i:%s');. I need to somehow compare this date with the date specified at the end of the contest and when arriving at the given time, no longer display the same.

I did not post code because I really could not develop anything, I need a light on how to proceed. I am developing the system in PHP pure, no framework. Can anyone help me?

1 answer

4


Make a condition on WHERE of query:

SELECT
  *
FROM [table]
WHERE [campo_data_expiracao] < NOW()

Something like that. Anything posts its table structure so I can be more specific in the answer.

  • Perfect, thank you!

  • Example of consultation: SELECT * FROM nome_tabela WHERE data_final < DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s');

  • No need to format the date NOW() already returns the correct date =)

  • Yes, but I need the time too, now only returns the date and not time.

  • @Jorgematheus must have something wrong in his config MySQL then why the NOW() must return date and time. 'The NOW() Function Returns the Current date and time. ' Ref: https://www.w3schools.com/sql/func_mysql_now.asp

  • Really, there was. Thank you!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.