PHP Daylight Savings Error When Dealing With Timestamps

Uncategorized No Comments »

Last night I was working on determining how long a user had been logged into a PHP application but was having a problem with subtracting timestamps and this is how I solved it.

I was storing two timestamps (as a UNIX timestamp) in the database. One designating the date-time the user logged into the application and the other the date-time of the last activity the user performed. Because I was using UNIX timestamps, which are just the number of seconds sine the UNIX epoch, I subtracted one from the other and used that difference as the input to the PHP function date().

I couldn’t for the life of me work out why the date function was saying that I was logged in for an hour longer than I should have been and it was driving me crazy. It turns out that the reason was that my timezone locale setting in PHP is ‘Europe/London’ and that this causes the date function to adjust for British Summer Time (GMT + 1) thus when I used my timestamp difference in the date() function it translated the difference into a readable format but also added an extra hour.

The solution is to use gmdate() which is identical to the date() function except that the time returned is in Grenwich Mean Time format.

How to check your premium bonds using Opera’s custom seach facility

Uncategorized 1 Comment »

If you’ve ever used opera or other browsers like konqueror then I’m sure you like the way you can search from the address bar by typing a custom shortcut and your search query. to search for ‘Premium Bonds Checker’ on google using Opera I’d just hit F8 (to get to the address bar) and then type ‘g Premium Bonds Checker’ and hit return because g is my shortcut for searching google.

This morning after I finally found it I checked my Premium Bonds holder’s number to see if I’d won (better luck next month). I thought to myself wouldn’t it be nice if I could tell Opera to check my holder’s number for me without having to go find it once a month.

The way I did it was to edit one of Opera’s custom search records. Read the rest of this entry »

WP Theme & Icons by N.Design Studio | Akismet has gobbled 340,147 spam comments...Mmmm Tasty :-)
Entries RSS Comments RSS Log in