My server is running PHP. I am using gmdate()
function to insert records into my database from server. I just wonder whether time zone is centralized by using gmdate()
function ?
Example:
One user creates entry from India and record is inserted into database
and
Second user create entry from USA/canada/france and record is inserted into database.
Is that time will be same as I used gmdate()
function while inserting record at server?
Well first of all, the function is called
gmdate
, notgmtdate
orgmatdate
. But I will assume these to be typos.GMT is an abbreviation for Greenwich Mean Time. It's name is a bit confusing to some, as in Greenwich, England, UK, they follow GMT during the winter and BST (British Summer Time) during the summer. This is the form of daylight saving time that is used in the UK. But GMT always refers to the standard time, and never the daylight time. In other words, GMT is a fixed time zone that does not follow daylight saving time, even though its physical locality does.
To clear up this but of confusion, we prefer to use the term UTC, which stands for Universal Coordinated Time (yes, the letters are out of sequence, and there's a reason for that, which is not relevant here). UTC is a timekeeping system that is agreed upon as an international standard. There are several parts to it's definition, but the important part here is that it defines its baseline as the same as GMT. Or depending who you ask, GMT is now defined the same as UTC. It doesn't matter - they are effectively the same.
And yes, no matter where in the world you are talking about it, you should get the same time when you use the
gmdate()
function to return it.The important reason to use UTC is that a server application should never depend on any local time zone. Who knows, one day you might pick up your data and move it to another location, or migrate it to the cloud, or interact with servers in other places. When doing so, if your times are in UTC, then your point of reference is all the same so everything will work well.
On the other hand, if you store local times and then you move somewhere else, then all your data has to be updated. Even if you never move - if your local time is somewhere like the USA or the UK or many other places, these places have daylight saving time as part of their time zone. This means you could be storing local times that are ambiguous for at least one hour of each year. That's not a good thing.
The alternative to UTC/GMT is to store a date+time+offset value. Then you will know both the local time, and how it relates to UTC (by the offset). But I would still reserve this for values where the local time is relevant. I mean, who really cares what the server's local time is anyway? If it carries no relevant business context, then you shouldn't introduce it into your application.