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
https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/
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

 

 

 

  • 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.