Scorchsoft Website Development Birmingham, West Midlands, UK.

View portfolio and testimonails

Questions?

< Back to news home page

PHP string to time hour out bug

Tue 12th Apr 2011

If you are using the php function strtotime() and find that the resulting timestamp is not correct then here is the solution

We were writing a simple function that needed the date string in the format "d-m-Y H:i:s" to be converted to a timestamp for processing. For some reason the resulting output was always an hour out. The problem was that the timezone was not specified in the date string.

 

Bad strtotime input:

strtotime('20-07-1988 12:00:00') 

Correct string to time input

strtotime('20-07-1988 12:00:00 GMT')  

 

A simple issue with a simple resolution but one that may not be obvious to spot by using the php strtotime api alone.


take on larger projects take on larger projects

FSB

Public Liability and Professional Indemnity Insured.

FSB

Member of the Federation
of Small Businesses.