Jump to content

Recommended Posts

I am extremely new to this, so please bear with me if I don't make sense.

 

In a php script, I add a datestamp to a field by using the now() function.

 

I am retrieving this field now from db, I have successfuly managed to get the date and convert it - select DATE_FORMAT(date,'%d-%m-%Y') as postedDate.

 

But I can't get the time at all. Can someone please help? I've tried using convert but I think I'm doing it wrong, because my php code just exits and the html then continues, after the following select statement.  If I take convert out it works, so I figure something is wrong with the convert statement.

 

mysql_query("SELECT asset_id, name, email, website ,comment, CONVERT(varchar(10), date, 108) as theTime, DATE_FORMAT(date,'%d-%m-%Y') as postedDate FROM Comment WHERE asset_id='lbi-type' ORDER BY date", $connection);

Link to comment
https://forums.phpfreaks.com/topic/198064-am-i-using-convert-wrong/
Share on other sites

Date and time are combined in a datetime field.

 

mysql_query("SELECT asset_id, name, email, website ,comment, DATE_FORMAT(date,'%h:%i:%s') as theTime, DATE_FORMAT(date,'%d-%m-%Y') as postedDate FROM Comment WHERE asset_id='lbi-type' ORDER BY date", $connection);

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.