Jump to content

Recommended Posts

I have a page with a form submission that goes to a MySQL table.  On a separate page, I want to pull individual submissions out and list the time they were submitted next to them.  Right now I use NOW() to gather the information from when the forms are submitted.  It comes out in this format: "2009-11-24 16:29:28" for instance.  I want to get rid of the date, the seconds, and set the hour back by one.  For instance, is there a quick and easy way to transform "2009-11-24 16:29:28" to "15:29:28" or even better to "3:29:28 PM?"

 

I'd like to keep the NOW() data in the original table, but when echoing it into the page that lists the info I want to manipulate it a little bit.

 

Any help would be greatly appreciated.  Thanks.

Link to comment
https://forums.phpfreaks.com/topic/182850-manipulating-now/
Share on other sites

Hi

 

I assume the field in the table is set to NOW()

 

This should get it for you

 

SELECT DATE_FORMAT(DATE_SUB(SomeDateField, INTERVAL 1 HOUR ),'%r') FROM SomeTable

 

or to show more control over the time format.

 

SELECT DATE_FORMAT(DATE_SUB(SomeDateField, INTERVAL 1 HOUR ),'%l:%i:%s %p') FROM SomeTable

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/182850-manipulating-now/#findComment-965142
Share on other sites

Hmmm, I'm still not doing something right.

 

Here is my code:

$result = mysql_query("SELECT * FROM tags WHERE name='Name1' ORDER by stamp DESC");

 

tags is the table name and 'stamp' is the name I gave the column where I assigned the NOW() values to go.  I tried plugging the code in, substituting for the *, but when I do the output just becomes blank.

 

I've tried messing around the the DATE_SUB feature on my the page with my Insert command and that doesn't work either. 

Link to comment
https://forums.phpfreaks.com/topic/182850-manipulating-now/#findComment-966325
Share on other sites

All the fields come out blank.  I set it up like this:

 

echo "<tr><td>";

  echo $row['stamp'];

  echo "</td><td>Tagged by: ";

  echo $row['user_id'];

  echo "</td></tr><tr><td colspan='2'>Tags: ";

  echo $row['tags'];

 

each individual submission has a value for each of those three variables, and the page comes up with the appropriate number of table rows (the appropriate number of echoes, in other words), yet it displays no values for each variable.

 

I currently have the MySQL set to a TIMESTAMP type...should I change this?  I could change it to TIME, perhaps.

Link to comment
https://forums.phpfreaks.com/topic/182850-manipulating-now/#findComment-966689
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.