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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.