Lumana Posted November 28, 2022 Share Posted November 28, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315593-echo-timestamp-from-mysql/ Share on other sites More sharing options...
ginerjm Posted November 28, 2022 Share Posted November 28, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315593-echo-timestamp-from-mysql/#findComment-1603007 Share on other sites More sharing options...
Barand Posted November 28, 2022 Share Posted November 28, 2022 19 minutes ago, Lumana said: then i tried like this but also not working: Describe "not working". That on its own tells us nothing. Quote Link to comment https://forums.phpfreaks.com/topic/315593-echo-timestamp-from-mysql/#findComment-1603011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.