Jump to content

how to store date time in MySql


starphp

Recommended Posts

Hi,

 

I have stored date time in a datetime datatype inside mysql database. But after formating like the following, it doesn't return the correct am/pm value. It always the return the value as am..Formating code that I used is:

 

date("M j \a\\t g:ia", strtotime($data['last_received_time'])); 

 

So I have tried with time() and it returns the result correctly with correct am/pm value. So it is better to store the time() in MySql than the DateTime ?

 

 

 

 

Link to comment
Share on other sites

The date() code you posted works. If it is only giving AM results, than that means that you are only giving it an AM value. I specifically asked you to echo an actual value to eliminate the input data as the cause of the problem.

Link to comment
Share on other sites

Sorry, I don't get what you suggested last time.

 

Anyway, I wish to make some explanation:

 

I have stored the datetime value in MySql like this

 

$date = date("Y-m-d h:i:s");

 

INSERT INTO table (fieldName) VALUE ('$date')

 

Then I read the value of date field from database and format the date as I mentioned above.. Then all values will be expressed on am.

 

But if I format the $date variable at the same time while inserting the value into database, it will return the value as pm..

 

So I am asking abt, whether I need to store the time() value (returned by php) in database instead of the value $date to get the correct am-pm

 

 

 

Link to comment
Share on other sites

  • 5 weeks later...

I had the same type of issue.  Needed to change 17:05:00 to 5:05 pm.

 

You can store into you data base table and format is back out. or format the time to you your data base right away

 

http://us2.php.net/manual/en/function.date.php

 

This is the page I found to reformat the information into my data base and now when I need the info back out it looks the way I need it.

 

Dave

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.