MyBB Community Forums

Full Version: Slight PHP Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,

I'm in need of some PHP help.

I have a form, when submitted, inserts a message and a TIMEDATE into a database.

The date is fine, but the time is three hours ahead of my localtime. Is it possible to use the strtotime function (or another function) to subtract three hours from the inserted time so I can echo it (with the correct time)?

Thanks in advance.
Perhaps a simple mathematical equation (subtraction) will work. However, as I have no idea how the timestamps are calculated but a math function would work the best I'd assume.
(2010-07-11, 11:44 PM)Scoutie44 Wrote: [ -> ]Perhaps a simple mathematical equation (subtraction) will work. However, as I have no idea how the timestamps are calculated but a math function would work the best I'd assume.

Hmmmm, I'm not too sure how I'd go by doing this.

Does anyone else have a good solution?

Thanks.
EDiT: One sec.

EDIT 2: http://www.electrictoolbox.com/correct-php-timezone/

Pasted wrong link -_-"
Just subtract 10800 from the timestamp and you'll be fine. (if my calculation was correct Toungue)
(2010-07-12, 12:32 AM)CAwesome Wrote: [ -> ]EDiT: One sec.

EDIT 2: http://www.electrictoolbox.com/correct-php-timezone/

Pasted wrong link -_-"

PHP displays the correct time, it's just MySQL doesn't display the correct time.

This script is on a shared host, so I have no way of changing the default timezone.

(2010-07-12, 12:36 AM)Imad Jomaa Wrote: [ -> ]Just subtract 10800 from the timestamp and you'll be fine. (if my calculation was correct Toungue)

I tried that, but I'll see if I can get it to work again...
(2010-07-12, 04:32 AM)Dutchcoffee Wrote: [ -> ]
(2010-07-12, 12:32 AM)CAwesome Wrote: [ -> ]EDiT: One sec.

EDIT 2: http://www.electrictoolbox.com/correct-php-timezone/

Pasted wrong link -_-"

PHP displays the correct time, it's just MySQL doesn't display the correct time.

This script is on a shared host, so I have no way of changing the default timezone.

(2010-07-12, 12:36 AM)Imad Jomaa Wrote: [ -> ]Just subtract 10800 from the timestamp and you'll be fine. (if my calculation was correct Toungue)

I tried that, but I'll see if I can get it to work again...

You are using time() to grab the time right? Subtracting from it should work fine.
(2010-07-12, 04:54 AM)Imad Jomaa Wrote: [ -> ]
(2010-07-12, 04:32 AM)Dutchcoffee Wrote: [ -> ]
(2010-07-12, 12:32 AM)CAwesome Wrote: [ -> ]EDiT: One sec.

EDIT 2: http://www.electrictoolbox.com/correct-php-timezone/

Pasted wrong link -_-"

PHP displays the correct time, it's just MySQL doesn't display the correct time.

This script is on a shared host, so I have no way of changing the default timezone.

(2010-07-12, 12:36 AM)Imad Jomaa Wrote: [ -> ]Just subtract 10800 from the timestamp and you'll be fine. (if my calculation was correct Toungue)

I tried that, but I'll see if I can get it to work again...

You are using time() to grab the time right? Subtracting from it should work fine.

Yes...And to insert the time, I'm using the NOW() to put the current time in the table. Is that the proper function to use?
@Dutchcoffee No, it would be pointless to grab the time using PHP then insert the time that MySQL generates. Its defining an unused variable which is very bad code practice. You should insert the time that PHP is generating since it is correct.
(2010-07-12, 05:43 AM)Sleepwalker Wrote: [ -> ]You should insert the time that PHP is generating since it is correct.

I'd do this, and what Imad said. The NOW function displays the current system date and time, which can widely vary - using PHP, you can resolve things like timezone differences. Smile
Pages: 1 2