I have written code that will read a text file and insert the data to a mysql table. The data is being inserted and everything is fine, except the time format. I need to convert the timezone from GMT to about 4 hours behind before it is inserted into the table, as I don't have access to the server. I do not know what function to use for this, if anyone can point me to what I should be using and an example that would be greatly appreciated.
Here is an example of the text file that is parsed and placed into the database. For the date column in the mysql database only "2010/05/17 20:00:49.606" is placed in and "GMT(05/17 16:00:49 -0400)" is ignored/skipped over when parsing. I could just skip the first date and use "05/17 16:00:49 -0400" instead, but the year is not listed there.
[text]
2010/05/17 20:00:49.606 GMT(05/17 16:00:49 -0400) ERROR MESSAGE Error description is shown here
2010/05/17 22:54:35.081 GMT(05/17 18:54:35 -0400) ERROR MESSAGE Error description is shown here
2010/05/17 20:01:33.464 GMT(05/17 16:01:33 -0400) ERROR MESSAGE Error description is shown here
[/text]
So when the data is actually in the database it would look like this:
Date column = 2010/05/17 20:00:49.606 | Note: I want this to change to 2010/05/17 16:00:49.606, about 4 hours behind, when it is inserted.
Message1 column = ERROR
Message2 column = MESSAGE
Description column = Error description is shown here
Thanks
Timezone Coversion Question [SOLVED]
Moderator: General Moderators
Timezone Coversion Question [SOLVED]
Last edited by spec36 on Wed Jun 23, 2010 7:57 pm, edited 1 time in total.
Re: Timezone Coversion Question
If you have
then you can
Code: Select all
2010/05/17 20:00:49.606 GMT(05/17 16:00:49 -0400) ERROR MESSAGE Error description is shown hereCode: Select all
$message = "the above";
$datetime = strtotime(strtok($message, ".") . " GMT");
$micro = strtok(" ");
date_default_timezone_set("wherever you are - check the manual page");
$datetime = date("Y/m/d H:i:s", $datetime) . "." . $micro;Re: Timezone Coversion Question [SOLVED]
You are awesome tasairis. Thanks so much, it works.