Timezone Coversion Question [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spec36
Forum Commoner
Posts: 28
Joined: Thu Nov 19, 2009 6:07 pm

Timezone Coversion Question [SOLVED]

Post by spec36 »

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
Last edited by spec36 on Wed Jun 23, 2010 7:57 pm, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Timezone Coversion Question

Post by requinix »

If you have

Code: Select all

2010/05/17 20:00:49.606 GMT(05/17 16:00:49 -0400) ERROR      MESSAGE  Error description is shown here
then you can

Code: 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;
spec36
Forum Commoner
Posts: 28
Joined: Thu Nov 19, 2009 6:07 pm

Re: Timezone Coversion Question [SOLVED]

Post by spec36 »

You are awesome tasairis. Thanks so much, it works.
Post Reply