avo Posted January 19, 2008 Share Posted January 19, 2008 Hi All if i have a bunch of dates formated as year / month / day Is there a way/function i would be able to select/pick out the closest date to NOW Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/86807-date/ Share on other sites More sharing options...
Barand Posted January 19, 2008 Share Posted January 19, 2008 Assuming they are in standard DATE columns SELECT mydatecol, ABS(DATEDIFF(mydatecol, NOW() )) as days ORDER BY days LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/86807-date/#findComment-443696 Share on other sites More sharing options...
avo Posted January 19, 2008 Author Share Posted January 19, 2008 Thank you How would the same question be achived please if i was getting the date in the same format from say a $_POST['date'] Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/86807-date/#findComment-443699 Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 Substitute mydatecol for your variable. Quote Link to comment https://forums.phpfreaks.com/topic/86807-date/#findComment-443700 Share on other sites More sharing options...
Barand Posted January 19, 2008 Share Posted January 19, 2008 do you mean find the nearest date to $_POST['date'] ? If so, use that instead of NOW() Quote Link to comment https://forums.phpfreaks.com/topic/86807-date/#findComment-443705 Share on other sites More sharing options...
avo Posted January 19, 2008 Author Share Posted January 19, 2008 Hi Sorry i think im confusing it $_POST['date1'] $_POST['date2'] $_POST['date3'] above holds a date in the format of year / month / day e.g 2008-19-01 the three posts are different dates how would i echo the closest date to todays date Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/86807-date/#findComment-443709 Share on other sites More sharing options...
Barand Posted January 19, 2008 Share Posted January 19, 2008 When you quote SQL functions like NOW() one naturally assumes you are talking about a DB table. Be a little more specific please. Quote Link to comment https://forums.phpfreaks.com/topic/86807-date/#findComment-443716 Share on other sites More sharing options...
avo Posted January 19, 2008 Author Share Posted January 19, 2008 All Help apprciated Hi Sorry i think im confusing it $_POST['date1'] $_POST['date2'] $_POST['date3'] above holds a date in the format of year / month / day e.g 2008-19-01 the three posts are different dates how would i echo the closest date to todays date Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/86807-date/#findComment-443728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.