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 Link to comment https://forums.phpfreaks.com/topic/269312-date-in-the-middle-between-to-dates/ 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. Link to comment https://forums.phpfreaks.com/topic/269312-date-in-the-middle-between-to-dates/#findComment-1384236 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. Link to comment https://forums.phpfreaks.com/topic/269312-date-in-the-middle-between-to-dates/#findComment-1384239 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". Link to comment https://forums.phpfreaks.com/topic/269312-date-in-the-middle-between-to-dates/#findComment-1384272 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? Link to comment https://forums.phpfreaks.com/topic/269312-date-in-the-middle-between-to-dates/#findComment-1384281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.