rahulkadukar Posted September 25, 2010 Share Posted September 25, 2010 <?php function time_convert($l_timestamp) { $l_timestamp = $l_timestamp * 86400; $time = date('Y-m-d',$l_timestamp); echo(date('Y-m-d',$l_timestamp)); //This does return (date('Y-m-d',$l_timestamp)); //This does not work return $time; // This does not work echo $time; //This does not work } time_convert(32155.0); ?> Can anyone help me, I am not getting the return parameter as I want Quote Link to comment https://forums.phpfreaks.com/topic/214386-function-with-time-not-returning/ Share on other sites More sharing options...
PaulRyan Posted September 25, 2010 Share Posted September 25, 2010 When you are returning a value, you must echo the function like the following to get any output. echo time_convert(32155.0); Use that instead of just time_convert(32155.0); Then change the function to... function time_convert($timeStamp) { $timeStamp = $timeStamp * 86400; $converted = date('Y-m-d',$timeStamp); return $converted; // This does not work } Tell me how it goes bud. Regards, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/214386-function-with-time-not-returning/#findComment-1115624 Share on other sites More sharing options...
rahulkadukar Posted September 25, 2010 Author Share Posted September 25, 2010 Sorry for making such a silly mistake, but my requirement is like this 1. I have time in a certain format which I am reading from a file 2. I want to convert it using the Function 3. Then want to write the converted output to a separate file The problem is the Function is not returning the converted value. Quote Link to comment https://forums.phpfreaks.com/topic/214386-function-with-time-not-returning/#findComment-1115625 Share on other sites More sharing options...
PaulRyan Posted September 25, 2010 Share Posted September 25, 2010 I see what you mean, but my solution should work tbh... <?php function time_convert($timeStamp) { $timeStamp = $timeStamp * 86400; // Set the timestamp $converted = date('Y-m-d',$timeStamp); // Convert the timestamp return $converted; // Return the timestamp } $convertedTime = time_convert(32155.0); ?> $convertedTime if the returned value that can be used how you wish. You can write that variable to the file and it will work. Regards, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/214386-function-with-time-not-returning/#findComment-1115630 Share on other sites More sharing options...
rahulkadukar Posted September 25, 2010 Author Share Posted September 25, 2010 Got it I was passing $data while the variable was stored in $date, I was correct all along but was passing the wrong value. Anyway thanks for all your help Quote Link to comment https://forums.phpfreaks.com/topic/214386-function-with-time-not-returning/#findComment-1115636 Share on other sites More sharing options...
PaulRyan Posted September 25, 2010 Share Posted September 25, 2010 Not a problem buddy, mistakes will be made Quote Link to comment https://forums.phpfreaks.com/topic/214386-function-with-time-not-returning/#findComment-1115638 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.