Jay2391 Posted March 5, 2007 Share Posted March 5, 2007 I want to convert that date('U'); number into a date can i do that ??? ??? $ut = date('U'); $rt = 1173128934 + 86400; $tbthere = $rt - $ut; echo "<br><br>$ut"; echo "<br><be>$rt"; echo "<br><be>$tbthere"; Quote Link to comment Share on other sites More sharing options...
JBS103 Posted March 5, 2007 Share Posted March 5, 2007 You want to convert date('U') into readable text? I don't understand. You can just change the "U" to something like "d-m-Y" and it will output it in a different format. Quote Link to comment Share on other sites More sharing options...
Jay2391 Posted March 5, 2007 Author Share Posted March 5, 2007 sorry if i didn't explain I want to change the date('U'); to day, month, year , time format Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted March 5, 2007 Share Posted March 5, 2007 date('d-m-Y'); Quote Link to comment Share on other sites More sharing options...
Jay2391 Posted March 5, 2007 Author Share Posted March 5, 2007 well i know how to do that .... but i need to do it in seconds first....why bacause what i am trying to do is set up a time with in 24hrs of the original time and have a auto counter that will keep track.... so with dates i can't figure out but with seconds i can do it really easy... so the question is can i convert that number into a actual date format???? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 5, 2007 Share Posted March 5, 2007 The second parameter of the date() function is the seconds since 1-1-1970, so <?php $u = date('U'); echo date('Y-m-d',$u); ?> Ken Quote Link to comment Share on other sites More sharing options...
Jay2391 Posted March 5, 2007 Author Share Posted March 5, 2007 cool thanks Quote Link to comment Share on other sites More sharing options...
Jay2391 Posted March 6, 2007 Author Share Posted March 6, 2007 why is my date not giving the correct info... ///////////I set up a static time and add one full day $rt = 1173128934 + 86400; ///////////////i get todays date $ut = date('U'); ////////////////i substract todays date to the static time and try to get the difference $tbthere = $rt - $ut; //////////////I convert and echo //////////i get the correct time echo date('Y-m-d / H:m',$ut); echo "<br>"; ////////////i get the correct time echo date('Y-m-d / H:m',$rt); echo "<br>"; Incorrect time ???? why is that ???? echo date('H:m',$tbthere); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2007 Share Posted March 6, 2007 The reason it is not displaying what you want is that the second argument for the date() function is an integer representing the number of seconds since 1-1-1970. What you are passing it is a number representing the number of second between two times. BTW, the format string you're using, "H:m", does not print hours & minutes. The "m" is for the number of the current month, you want to use the "i" to get minutes -- "H:i". One solution to your problem would be to get the the number of seconds since 1-1-1970 of any date at midnight, add your value to it and format that number as "H:i": <?php ///////////I set up a static time and add one full day $rt = 1173128934 + 86400; ///////////////i get todays date $ut = date('U'); ////////////////i substract todays date to the static time and try to get the difference $tbthere = $rt - $ut; //////////////I convert and echo //////////i get the correct time echo date('Y-m-d / H:i',$ut) . '<br>'; ////////////i get the correct time echo date('Y-m-d / H:i',$rt) . '<br>'; // Echo the correct formatted difference echo date('H:i',strtotime('3/3/2007 00:00') + $tbthere) . '<br>'; ?> Ken Quote Link to comment Share on other sites More sharing options...
Jay2391 Posted March 6, 2007 Author Share Posted March 6, 2007 May be i miss read something I see that it dosen't really work 2007-03-06 / 12:14 correct current time 2007-03-07 / 16:08 day and time expiration 03:54 ---this should be 27:54 because this is how many hours to reach the exp date and time I know you mention about getting a time at midnight .... strtotime('3/3/2007 00:00') but you did that already .... so what do you mean another substraction then ??? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 6, 2007 Share Posted March 6, 2007 My method only works if the difference is less than a day. As a general method, try this: <?php $diff_hours = floor($tbthere / 3600); $diff_mins = floor($tbthere % 3600)/60; echo sprintf("<br>%02d:%02d",$diff_hours,$diff_mins); ?> Ken Quote Link to comment Share on other sites More sharing options...
Jay2391 Posted March 6, 2007 Author Share Posted March 6, 2007 my plan is to alway be less than a day but the extra info and code didn't hurt .... thanks that work not quite sure how you did it but it works, I willl take a closer look at the code and try to understand i hate when I am all confuse, LOL ..Thanks Again!!!! 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.