levyta Posted October 10, 2012 Share Posted October 10, 2012 I'm looking for a way to find the date between to date. any suggestions? For example: Date1 = "2012-01-01"; Date2 = "2013-01-01"; I want to get "2012-07-01"; Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 10, 2012 Share Posted October 10, 2012 How did you come up with 2012-07-01 in order to write the question? Now convert that process into code. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 10, 2012 Share Posted October 10, 2012 php > $s = strtotime('2012-01-01'); php > $e = strtotime('2013-01-01'); php > echo date('Y-m-d', ($s + $e)/2); 2012-07-02 Note that your math is wrong. 7/2 is halfway through the year, not 7/1. Months are not all the same length. Also, this probably won't work right on 32-bit systems. Quote Link to comment Share on other sites More sharing options...
levyta Posted October 10, 2012 Author Share Posted October 10, 2012 It doesn't work. I've tried your suggestion and received "1970-01-01". Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 10, 2012 Share Posted October 10, 2012 My "suggestion" was a copy and paste of working code being executed by the PHP interpreter. What did you try? Quote Link to comment 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.