prince198 Posted August 24, 2008 Share Posted August 24, 2008 hi and nice sunday i look for funcion like SELECT FROM_DAYS() ofv mysql but in php so for example : <?php mysql> SELECT FROM_DAYS(729669); -> '1997-10-07' ?> but i'm looking this function in php thaks for helping Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/ Share on other sites More sharing options...
DeanWhitehouse Posted August 24, 2008 Share Posted August 24, 2008 As far as i know , there isnt a pre-made one. You will need to write your own. Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/#findComment-624542 Share on other sites More sharing options...
prince198 Posted August 24, 2008 Author Share Posted August 24, 2008 i tried with strotime and mktime with no ???result Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/#findComment-624544 Share on other sites More sharing options...
DeanWhitehouse Posted August 24, 2008 Share Posted August 24, 2008 ok, show your try and we will help show you where it went wrong Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/#findComment-624546 Share on other sites More sharing options...
prince198 Posted August 24, 2008 Author Share Posted August 24, 2008 ok in my sql there two function first is to_days() so if i write select to_days('2008-01-01') i wil have result 733407 second function is from days select from days (733407) i wil have result 2008-01-01) in php to have like function to_days i had to do this <?php $days = to_days("2008-01-01"); function to_days ($date) { $days = round(strtotime($date) / (60 * 60 * 24))); return 719527 + $days; } and i will have 733407 but for from days i tried to reverse the operation 733407-719527/86400 but i don't see how i get date in forme yyyy-mm-dd i hpe you unterstand Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/#findComment-624548 Share on other sites More sharing options...
Barand Posted August 24, 2008 Share Posted August 24, 2008 [pre] mysql> select TO_DAYS('1970-01-01'); +-----------------------+ | TO_DAYS('1970-01-01') | +-----------------------+ | 719528 | +-----------------------+[/pre] therefore <?php function from_days ($d) { $t = ($d - 719528) * 86400; return date ('Y-m-d', $t); } echo from_days(729669); // --> 1997-10-07 ?> Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/#findComment-624553 Share on other sites More sharing options...
prince198 Posted August 24, 2008 Author Share Posted August 24, 2008 thank you its work thank you very much problem resolved Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/#findComment-624556 Share on other sites More sharing options...
Aeglos Posted August 24, 2008 Share Posted August 24, 2008 733407 is the number of days. Convert it to the current number of seconds and then use strftime(); <?php $time = 733407*24*60*60; $date = strftime("%Y-%m-%d", $time); echo $date; //Should output YYYY-MM-DD ?> Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/#findComment-624560 Share on other sites More sharing options...
prince198 Posted August 24, 2008 Author Share Posted August 24, 2008 its work also thank you so much i have now 2 solution Quote Link to comment https://forums.phpfreaks.com/topic/121150-solved-function-php-like-from_days-of-mysql/#findComment-624563 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.