-
I have a report which will give me the time field as
$time='Wed, 25 Aug 2010 13:43:38 +0000'.I am currently storing this into my MySql DB exactly like this and generating a custom report with the same time. I am in EST time so i want to know how i can change the $time field to show it according to'Wed, 25 Aug 2010 09:43:38 '. i want to remove that +0000 and change the timings to EST. I want to store it into the DB in this format, which i saved as a varchar. -
I also want to be able to split this $time and save it as
$timeday='Wed, 25 Aug 2010'and$timetime='09:43:38'. splitting it by counting the no of characters might work but problem would arise when it is likeWed, 9 Aug 2010or if i get the report time asWed, 1 Sept 2010, which i am not sure whether the month would always be 3 characters or can change.
Thank you 🙂
First off, never store a datetime as varchar. You just made it completely useless. Always store it in a special datetime format. This way you can do all sorts of things, searching, sorting etc.
When you need to recover your information you can format the output in anyway you want. You can also subtract just the parts you need when requesting from the database.
See: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
To store your data in the correct way.
Use string to time, and then format it into mysql datetime format.
Postgresql supports timezone, if I’m correct mysql does not. So you can create a function when requesting the data from the database to display it anyway you need.
Make sure you have set a default timezone in php or else you will get an error.
Store into mysql database
You first create correct mysql format:
// http://php.net/manual/en/function.strtotime.php
When requesting from database you can use the database to format it in anyway you need.
example (mysql):