liquidentropy Posted January 10, 2008 Share Posted January 10, 2008 Can anyone help me with this i'm not sure how to do it. Still learning PHP and I cant quite figure it out Write a function that takes two arbitrary dates in the format 'YYYY-MM-DD' and calculates the amount of days between them without using any php date functions. Thanks Link to comment https://forums.phpfreaks.com/topic/85393-calculating-amount-of-days-between-two-dates-without-using-date-functions/ Share on other sites More sharing options...
cooldude832 Posted January 10, 2008 Share Posted January 10, 2008 try <?php //Start $day1 = "2008-01-10"; //End $day2 = "2008-01-15"; //Time in seconds $time = date("U",strtotime($day2))-date("U",strtotime($day1)); //86400 seconds in a day so $days = round($time/86400); echo "There are ".$time." seconds between ".$day2." and ".$day1." <br />and ".$days." days between ".$day2." and ".$day1."."; ?> give that a go Edit: missed a ) so if you copied it once recopy it Link to comment https://forums.phpfreaks.com/topic/85393-calculating-amount-of-days-between-two-dates-without-using-date-functions/#findComment-435685 Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 But that uses the date function, cooldude82. Link to comment https://forums.phpfreaks.com/topic/85393-calculating-amount-of-days-between-two-dates-without-using-date-functions/#findComment-435693 Share on other sites More sharing options...
cooldude832 Posted January 10, 2008 Share Posted January 10, 2008 But that uses the date function, cooldude82. and I quote php.net Requirements No external libraries are needed to build this extension. Installation There is no installation needed to use these functions; they are part of the PHP core. If its deafult installed you can't say I don't want to use it not a valid argument Link to comment https://forums.phpfreaks.com/topic/85393-calculating-amount-of-days-between-two-dates-without-using-date-functions/#findComment-435697 Share on other sites More sharing options...
liquidentropy Posted January 10, 2008 Author Share Posted January 10, 2008 Good solution but still uses date functions. Is there any way to do it without using the date functions. ??? Link to comment https://forums.phpfreaks.com/topic/85393-calculating-amount-of-days-between-two-dates-without-using-date-functions/#findComment-435724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.