Hello Torkil,

> I have a field in my mysql database containing date&time on the format
> YYYY-MM-DD HH:MM:SS (24-hour format)
> Now. I want to output this as follows: DD.MM.YY at HH:MM:SS
> Currently I do this by this function:
> function convert_datetime($in){
> $return = substr($in,8,2) . "." . substr($in,5,2) . "." . substr($in,2,2) .
> " at " . substr($in,11,8);
> return $return;
> }
> Is there a better way? Either with mysql or php?

=yes, please check the MySQL manual's section on Time/Date functions. There is a 
surprising list of them, and
one will satisfy your needs more efficiently that the PHP routine.

> Now. Another problem. Since my webserver is in the states, and I live in
> Norway, I get a 7 hour time difference.
> So when I do date("Y-m-d H:i:s") I get a time that is 7 hours wrong.
> Any idea as to how I can correct this to be 7 hours later (that is: 12 in
> server time is really 19 where I live) in an easy way?

=let me offer you further grounds for confusion: MySQL doesn't care! MySQL keeps no 
sense/location in time, it
is fed a time/date value and it stores it. End of story.

=If you ask PHP for time (and date) information, it will be taken from the server. How 
then is it supposed to
work out where you/the client is. If you always want to adjust a server-based time by 
seven hours, then that is
easy enough. If however you want to give local-time to the client, life gets much more 

=Either way, your reading will be from the PHP manual, and again the time-date 
facilities. Take careful note of
the fact that there are two sets of functions, one for server time and the other for 
UTC (GMT or Zulu time).
Note also that there are ways of getting time zone information/differences too.

=I found it a lot easier to accept times from the client, and immediately convert them 
to UTC before storage in
MySQL. When I retrieve data it is always stated to be UTC. The beauty of this is that 
I don't have to beat my
brains trying to figure out the international implications of "Summer Time" and the 
twice yearly discontinuities
so-caused. However this uniform and 'tidy' solution may not suit your requirements...


PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to