Welcome Guest | Login

NOW() does not recognise today

I have NOW() in a script written by my nephew which worked on the server where my website used to be hosted.

 
$query="SELECT event_id, event_title, event_title_2 ,event_date, event_time, event_content FROM $table WHERE event_date >= NOW() AND event_date <= date_add(NOW(), INTERVAL 7 DAY) ORDER BY event_date ASC $limit";

This doesn't list the event on the current date but starts with events on the following day ie it sees NOW() as tomorrow.

2008-05-20 08:35 AM

Hi Duomus,

>>This doesn't list the event on the current date but starts with events on the following day ie it sees NOW() as tomorrow.

Please execute a command  "Select Now();" from your mysql prompt and check the current date of system with the date obtained from the application.  

2008-05-20 10:30 PM

I did as you suggested and the the date returned was the current date and the same as shown on the webpage. http://www.hampsteadparishchurch.org.uk/data/calendar1.php

I have put an event on the page for 23rd, 24th,25th 26th and 27th but the current day (23rd) does not show.

the script is

 $query="SELECT event_id, event_title, event_date, event_time, event_content FROM $table WHERE event_date >= NOW() ORDER BY event_date ASC $limit";

2008-05-23 05:52 PM

That should work - but for the time being you should be able to simply substitute with:

$query="SELECT event_id, event_title, event_date, event_time, event_content FROM $table WHERE event_date >= " . strftime("%Y-%m-%d %H:%M:%S") . " ORDER BY event_date ASC $limit";

2008-05-24 12:37 AM

Thank you for your response but I am afraid that gives me

Query failed: SELECT event_id, event_title, event_date, event_time, event_content FROM hpc_events WHERE event_date >= 2008-05-24 13:56:18 ORDER BY event_date ASC

If I remove %H:%M:%S it makes a list but the list is of everything even the past events.



2008-05-24 02:14 PM

Hmm - you may need to put single quotes:

$query="SELECT event_id, event_title, event_date, event_time, event_content FROM $table WHERE event_date >= '" . strftime("%Y-%m-%d") . "' ORDER BY event_date ASC $limit";

2008-05-24 03:17 PM

Yea!!

Thank you very much.

Do you have any idea why the original script failed, it worked on the server where the site was hosted?

2008-05-24 04:37 PM

Not sure, let us know if you notice any other problems. I'm glad it working for you now.

2008-05-25 02:31 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!