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 7800813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:45:25+00:00 2026-06-02T00:45:25+00:00

I have a query that returns a date, and I’d like to format it

  • 0

I have a query that returns a date, and I’d like to format it before I display it to users on my page. However, when I use format, the date appears to be null (displays year 1969). Here is the code that gets the data:

$sql = 'SELECT u.username, td.postingText, td.createdOn, td.lastUpdated
        FROM threadDetails td, users u
        WHERE blogThreadId = ?
        AND td.userId = u.userId
        order by td.createdOn DESC';
$stmt = $conn->stmt_init();
$stmt->prepare($sql);
$stmt->bind_param('s', $blogThreadId);
$stmt->bind_result($username, $postingText, $createdOn, $lastUpdated);
$stmt->execute();
$stmt->store_result();

$numrows = $stmt->num_rows;
while ($stmt->fetch())
{
    $rowofdata=array(
        'username' => $username,
        'postingText' => $postingText,
        'createdOn' => $createdOn,
        'lastUpdated' => $lastUpdated,
    );  
    $results[] = $rowofdata;
}   
$stmt->close();

When I print it out with the following code (in a different function):

foreach ($threadData as $threadDetailItem)
{
    $msg = sprintf ("<tr>%s %s %s %s %s </tr>\n",
        "<td>" . $threadDetailItem['threadTitle'] . "</td>", 
        "<td>" . $threadDetailItem['username'] . "</td>", 
        "<td>" . $threadDetailItem['createdOn'] . "</td>", 
        "<td>" . $threadDetailItem['threadCount'] . "</td>", 
        "<td>" . $threadDetailItem['lastUpdated'] . "</td>");
    echo $msg;
}

It prints out (for my created On or last Updated fields):

2012-04-15 16:14:55

When I replaced the portion of the sprintf line:

        "<td>" . $threadDetailItem['createdOn'] . "</td>", 

with:

        "<td>" . date("F j, Y, g:i a", $threadDetailItem['createdOn']) . "</td>", 

I get

“December 31, 1969, 7:33 pm” and a message in my phplog stating a non-well formed numeric value encountered. What do I need to do get the the right date displayed correctly? I’ve tried changing the sprintf from %s to %d, but that doesn’t work.

Thanks in advance for your suggestions.

  • 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-06-02T00:45:26+00:00Added an answer on June 2, 2026 at 12:45 am

    It’s because $threadDetailItem['createdOn'] is a string, and the date() function expects a numeric timestamp. Use the strtotime() PHP function to convert the string to a timestamp first:

    date("F j, Y, g:i a", strtotime($threadDetailItem['createdOn']))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that returns one row. However, I want to invert the
i have a query that returns some users related to a specific user (Bob).
I have a query that returns data with group category and some details like
I have a query (A) that can returns multiple rows in date order: SELECT
I have a big flinq query that returns, among many other things, a date
I have the following sql query that returns the DateTime-formatted information in Month format
I have a query that returns a result set similar to the one below:
I have a query that returns a string, as well as an escape character
i have a query that returns rows that i want, e.g. QuestionID QuestionTitle UpVotes
I have a query that returns a lot of data into a CSV file.

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.