Jump to content

PHP Date comparisons


EchoFool

Recommended Posts

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 ?

 

Link to comment
https://forums.phpfreaks.com/topic/185652-php-date-comparisons/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/185652-php-date-comparisons/#findComment-980416
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.