Jump to content

Correct query to convert timestamp to readable format in php


Atrix
 Share

Recommended Posts

Hi,I am trying to make a query that grabs the timestamp in the mysql database and convert it in to a readable format using php.I am slowly learning php, but can't seem to make it work.I was wondering how I would make that query so I can then echo the format.

Link to comment
Share on other sites

If the data is stored in the database as a date, timestamp, etc field, then it's better to do the conversion in SQL when you select the value. You can also use PHP's strtotime function to parse most formats. If it's stored as an integer Unix timestamp then you can use PHP's date function to format it.

Link to comment
Share on other sites

I tried to do it a in PHP where I did the SQL date() function; and it show's nothing (see code below):

<?php	     $pdt = mysql_query("SELECT DATE(pubdate) FROM wm_minister_msg where sysdate() >= pubdate and sysdate() < expiredate");	     $rowdt = mysql_fetch_array($pdt);	     echo $rowdt['pubdate'];	?>

Link to comment
Share on other sites

The column won't be called pubdate, it'll be called DATE(pubdate). Also, check for errors.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...