EchoFool Posted December 18, 2009 Share Posted December 18, 2009 Hey I've done a few date comparisons before but nothing with this format so im kinda confused. I have a field in my table which is "text" and the input format is mm/dd/yyyy . Im trying to get php to mathematically return how many days passed from "now" on my server which using the dd/mm/yyyy. How can this be done? If at all ? Quote Link to comment https://forums.phpfreaks.com/topic/185652-php-date-comparisons/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 18, 2009 Share Posted December 18, 2009 After you convert to using a proper DATE data type, you can simply use the mysql DATEDIFF() or the TIMESTAMPDIFF() function in your query to get the number of days between any two dates. Quote Link to comment https://forums.phpfreaks.com/topic/185652-php-date-comparisons/#findComment-980310 Share on other sites More sharing options...
EchoFool Posted December 18, 2009 Author Share Posted December 18, 2009 Yeah i use DateDiff But if i convert dd/mm/yyyy and compare that with the mm/dd/yyyy the values are not guna match because its backwards. Quote Link to comment https://forums.phpfreaks.com/topic/185652-php-date-comparisons/#findComment-980311 Share on other sites More sharing options...
gevensen Posted December 19, 2009 Share Posted December 19, 2009 convert your table from text to date use the format yyyy-mm-dd ie for ex 2009-12-25 convert the string you want to compare 12/25/2008 to 2008-12-25 for example using explode then after they are both in the same format you can use mysql comparisons in your query for example select * from table where date between '2008-12-25' and table.date where table.date for example would be 2008-12-25 the big thing is set up you table correctly and have your dates properly formatted after they are properly formatted you can also convert them to unix time() for ex $date1=time("2009-12-25"); $date2=time("2008-12-25"); then you would get a measurement in seconds which you could use in a slightly different way if you chose Quote Link to comment https://forums.phpfreaks.com/topic/185652-php-date-comparisons/#findComment-980416 Share on other sites More sharing options...
EchoFool Posted December 19, 2009 Author Share Posted December 19, 2009 Okay ill see what i can do - thanks. Quote Link to comment https://forums.phpfreaks.com/topic/185652-php-date-comparisons/#findComment-980437 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.