Jump to content

Recommended Posts

You can use MySQL's NOW() function to return the current time into the query string. It's faster and more efficient, too.

 

SELECT field1, field 2 FROM table WHERE your_time_field < NOW()

 

Well the problem is that the time is a variable and will be changing.  The first time the query runs it should pull results where time is less than the current time.  The second time it will pull results where the time is less than the last row of the first query.  That's why I need to make it a php variable. I also need it to be formatted so that I will be able to compare it to mysql

Link to comment
https://forums.phpfreaks.com/topic/235323-date-time-format/#findComment-1209286
Share on other sites

For the first query you can use the NOW() function as above, For the second one, since the result is (presumably) already formatted from the DB, why can't you just use it directly?

 

Wouldn't that require me to duplicate the same function?  It wouldn't be better to just pass date/time as a parameter?

Link to comment
https://forums.phpfreaks.com/topic/235323-date-time-format/#findComment-1209288
Share on other sites

I don't think I can really answer with any degree of accuracy without seeing the code, but if you feel supplying the current time from php to the function as a parameter would be best, you can use this.

 

$now = date( 'Y-m-d H:s:i', time() );

Link to comment
https://forums.phpfreaks.com/topic/235323-date-time-format/#findComment-1209289
Share on other sites

I don't think I can really answer with any degree of accuracy without seeing the code, but if you feel supplying the current time from php to the function as a parameter would be best, you can use this.

 

$now = date( 'Y-m-d H:s:i', time() );

 

I'm not sure why but that doesn't seem to be working.  I have...

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '00:23:09 ) UNION ALL ( SELECT ' at line 28

 

$now = date( 'Y-m-d H:s:i', time() );
$news_feed = fetch_personalized_news_feed($user_info['uid'], $now);

 

WHERE users.id = ${uid}
AND partners3.approved_date < ${time}

 

Is that the correct formatting?

 

Link to comment
https://forums.phpfreaks.com/topic/235323-date-time-format/#findComment-1209296
Share on other sites

It would need to be in quotes in the query string. You could possibly inject the quotes with the variable as part of the parameter, but you'll need to try it to see if it works. If not, just edit the query string to include them.

 

$news_feed = fetch_personalized_news_feed($user_info['uid'], "'$now'");

Link to comment
https://forums.phpfreaks.com/topic/235323-date-time-format/#findComment-1209298
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.