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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:15:07+00:00 2026-05-20T10:15:07+00:00

i found an old blog script (very old) kicking around on my PC. im

  • 0

i found an old blog script (very old) kicking around on my PC. im having troubles with fetching the date and time from my DB to display in PHP. Can someone help me.
This is my MySQL DB setup.

CREATE TABLE blog_posts (
  id int(11) NOT NULL auto_increment,
  title varchar(30) NOT NULL default '',
  news text NOT NULL,
  poster varchar(15) NOT NULL default '',
  date timestamp(14) NOT NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

And this is what im using to send a post:

<?php

include "db.php";   
    $title=$_POST['title'];
    $news=$_POST['news'];
    $poster=$_POST['poster'];

    $query="INSERT INTO $blogposts (title, news, poster) VALUES ('$title', '$news', '$poster')";
    $result=mysql_query($query) or die (mysql_error());

    mysql_close();

    header("Location: post.php");
?>

And finally this is what im using to call the date on the front-end:

<?php echo "posted on: - ".$day.".".$month.".".$year." at ".$hour.":".$min; ?>

I’m no expert (clearly) but the call for the date doesnt look right to me. Anyone have any ideas on how i could make it work, or even make it better??

EDIT::

<?php

    include "db.php";

//query
    $query="SELECT * FROM ".$blogposts." ORDER BY id DESC LIMIT 0,$limit ";
    $result=mysql_query($query) or die (mysql_error());

//loop
    while($row=mysql_fetch_array($result))
    {
$querycomment = "SELECT ID FROM ".$newscomments." WHERE newsid=".$row['id'];
$resultcomment=mysql_query($querycomment) or die (mysql_error());
$num_rows = mysql_num_rows($resultcomment);

    ereg("^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})",$row['date'],$res);
    $year=$res[1];
    $month=$res[2];
    $day=$res[3];
    $hour=$res[4];
    $min=$res[5];
    $sec=$res[6];


?>

Thanks

  • 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-20T10:15:08+00:00Added an answer on May 20, 2026 at 10:15 am

    As date column has TIMESTAMP data type and got not null constraint so it will have default current_timestamp value if no data posted on date column while inserting. see mysql timestamp ref manual.

    So to achieve a result that you ask you can try fetch that data by using code like this:

    $sql = "select id, title, news, poster, DATE_FORMAT(date,'%d.%m.%Y at %k:%i') as posteddate from blog_posts";
    $result = mysql_query($sql);
    while ($row = mysql_fetch_assoc($result)) {
        echo $row["title"]."<br/>";
        echo "By : " . $row["poster"]."<br/>";
        echo "posted on: -  " . $row["posteddate"]."<br/>"; //"posted on: - 03.03.2011 at 7:35"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every LINQ blog I found there seemed around 2 years old, I understand the
I have recently found old (very old) laptop and though that it might be
I have found an old script written in C and when I try to
I have a library ( based on code found in an old blog post
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
This morning we found an old chunk of code that was causing a library
I need to get the current context given an entity I found this old
I found this question in an old question in your website so i thought
I just found this in some old code, and I'm not sure what it
We've found a bug in old code where connections aren't being closed. It's an

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.