Jump to content

echo timestamp from mysql


Lumana

Recommended Posts

I am trying to fetch timestamp data from mysql but its not working, can anyone please help me out of this. Thanks in Advance

At first I tried like this but not working: 

<?php

include 'database.php';

$sql=mysqli_query($con,"SELECT * FROM article where alias='how-to-do-math-equation'");

$row=mysqli_fetch_assoc($sql);

echo $row['update_time'];

?>

 

then i tried like this but also not working:

 

 

<?php

include 'database.php';

$sql=mysqli_query($con,"SELECT * FROM marathons where alias='standard-chartered-marathon-KL'");

$row=mysqli_fetch_assoc($sql);

$posted_at = ($row['update_time']);

echo $posted_at;

?>

I want to echo timestamp data like this :  2022-11-28 14:28:58

Link to comment
Share on other sites

Take a look at a mysql manual and read up on the date_format function.  It will convert any datetime,date or time type column to a readable string format, which is what you want.

BTW - it is not recommended to use the * in query selections.  Always specify the column names that you want in order to avoid future confusion about what you are querying for and to make future maintenance less problematic.  Another personal foible is to define your query statement as a php variable and reference that instead of burying your query inside a statement.  That way you can easily echo it out while debugging your script.  Another thing to do is always check your query results to be sure you actually got something.  You should do the same for anything that will do something external to php such as file opens, connection opens, etc.

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.