Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6620941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:10:22+00:00 2026-05-25T21:10:22+00:00

I am trying to include a function from one PHP file into another and

  • 0

I am trying to include a function from one PHP file into another and use the function with a parameter and get a return value. All is good until I run the function, where PHP dies. How can I fix this?

timestamp_reader.php:

<?php
function get_time($timestamp){
    $year = substr($timestamp, 0, 4);
    $month = substr($timestamp, 4, 2);
    if(substr($month, 0, 1) == "0")
        $month = substr($month, 1, 1);
    $day = substr($timestamp, 6, 2);
    if(substr($day, 0, 1) == "0")
        $day = substr($day, 1, 1);
    $hour = substr($timestamp, 8, 2);
    if(substr($hour, 0, 1) == "0")
        $hour = substr($hour, 1, 1);
    $hour = intval($hour);
    if($hour > 12){
        $hour = $hour - 12;
        $pm = true;
    }else $pm = false;
    $minute = substr($timestamp, 10, 2);
    if(substr($day, 0, 1) == "0")
    $day = substr($day, 1, 1);
    if($pm) $minute .= " PM";
    else $minute .= " AM";

    return $month . "/" . $day . "/" . $year . " " . $hour . ":" . $minute;
}
?>

And the file that I want access to this function (note, it is in a different directory):

...some PHP code before this...
include "/project/includes/timestamp_reader.php";
while($row=mysql_fetch_array($result)){
    $msg = $row['message'];
    $timestamp = $row['timestamp'];
    $time = get_time($timestamp);
    echo "<p><center>" . $time . " " . $msg . "</center></p>";
}

I’d like to figure this out and use it for a variety of functions so I don’t have to type them in every time if possible. Also, I need something similar for creating project-wide variables.

Anyway, thanks for any and all help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:10:23+00:00Added an answer on May 25, 2026 at 9:10 pm

    Why not use the date() function within PHP?

    For example,

    $timestamp = "1316922240";
    echo date("m-j-Y", $timestamp);
    

    Will print out 09-24-2011 based on that time stamp for right now – if the timestamp was from yesterday, the date echo-ed will be yesterday.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to include a .js file into a php file. My folder
I'm trying to use node_load to pass php variables (as variables!) from one node
I'm trying to cobble together a php style include function for javascript. The route
I am trying to include a value from a database table within the value
I am trying to include the Zend_Service_Amazon_S3 file by using require_once 'Zend/Service/Amazon/S3.php'; I have
I'm trying to use a Class_B function in one of Class_A's functions. But a
What I'm trying to do is dynamically include one or more js files from
I'm trying to use jQuery.post() function to retrieve some data. But i get no
I have a file that corrals my re-usable functions into one file ( functions.php
Trying to include ThickBox (from http://jquery.com/demo/thickbox/ ) in an ASP.NET application. Visual Studio is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.