|
Posted by Jerry Stuckle on June 22, 2008, 2:29 pm
Please log in for more thread options
AnrDaemon wrote:
> Greetings, Jerry Stuckle.
> In reply to Your message dated Sunday, June 22, 2008, 06:19:16,
>
>> WebCM wrote:
>>> There is a function: http://paste.ubuntu.com/21865
>>>
>>> It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: [b]datetime[/
>>> b]. If date is the same as today, the function returns "Today". There
>>> is one problem. This function does not recognize time zones.
>>>
>>> How to adjust date to user's time zone? Is converting to timestamp()
>>> and then to format readable to visitors the one and only solution
>>> (e.g. strtotime() + date() OR DateTime object)? Perhaps, it's possible
>>> to solve this problem with mathematical operations (it needs more
>>> combinations). Has someone dealed with time zones?
>>>
>>> If I stored timestamps instead of datetime, PHP would deal with time
>>> zones automatically (date() with 2nd parameter). However, it will be
>>> harder to display "Today", "Tomorrow", "Yesterday"...
>>>
>>> In conclusion, this function must return formatted string in proper
>>> time zone. It must return "Today" and optionally "2 minutes ago" when
>>> needed. How to do it? Is it better to make mathematical operations? Or
>>> should I use build-in functions like: mktime(), strftime(), date(),
>>> strtotime()...? Everything must be very FAST.
>>>
>
>> First of all, you don't necessarily know the client's timezone.
>
> Forums typically has such configuration option for registered users.
> How can you missed this simple point?
>
Which has absolutely nothing to do with the ops question - or the
problem at hand. How can you miss this simple point? Oh, yes. I
forgot who you are. Now I know how you could miss something so simple.
>> To use such a function, you need have access to the date/time stored in
>> the database. Storing as a datetime or timestamp has it's advantages -
>> you can retrieve it in a number of formats, such as UNIX_TIMESTAMP or
>> any number of other formats. It also makes it easy to sort on this
>> field. For instance, to get the format you need would be quite easy
>> with MySQL's DATEFORMAT function, i.e.
>
>> DATEFORMAT(datecol, '%Y-%m-%d %H:%i:%s');
>
>> Or, if the column is in unixtime, a simple FROM_UNIXTIME() call works.
>
> Will it return "today" or "yesterday" as OP requested?
>
That is not what the op requested. Learn to read.
>> The point is - there are a lot of options here - all of which work.
>> Don't restrict yourself to PHP - look at the database functions, also.
>
>> As for fast - this is not the time to be worried about speed - that's
>> over-optimizing. Rather, if it's a problem, later you can look at your
>> code and determine how to speed it up. Unless you write some awfully
>> inefficient code, this conversion will NOT be your problem.
>
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|