Jump to content

Function with Time not returning


rahulkadukar

Recommended Posts

<?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

Link to comment
https://forums.phpfreaks.com/topic/214386-function-with-time-not-returning/
Share on other sites

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.