Adobe Dreamweaver Forums



Last 10 THreads :         spry menubars not lining up in IE (Last Post : coftscootourb - Replies : 148 - Views : 536 )           »          display strips leading 0 (Last Post : Azadi - Replies : 1 - Views : 2 )           »          Image enlarge on mouse-over (Last Post : accicalacrism - Replies : 5 - Views : 190 )           »          net links (Last Post : almanson - Replies : 2 - Views : 3 )           »          mx 04 versus cs3 pro (Last Post : richard - Replies : 0 - Views : 1 )           »          Locking resize handles in browser. (Last Post : Jasper Thayer - Replies : 3 - Views : 4 )           »          Flash buttons don't work (Last Post : Murray *ACE* - Replies : 2 - Views : 3 )           »          Does DW CS3 write better php than DWMX2004? (Last Post : Murray *ACE* - Replies : 1 - Views : 2 )           »          PagesThemselves Look OK After Removing Link, But WhenSecond Nav Bar is Used Formatting is Lost (Last Post : Murray *ACE* - Replies : 5 - Views : 6 )           »          Preview with CS4 or CS3 on OS10.5.4 gets wrong URL path (Last Post : Murray *ACE* - Replies : 7 - Views : 8 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Dreamweaver: Main > Dreamweaver Application Development
 
Tags:

Reply
  #1 (permalink)  
Old 06-12-2008, 12:32 PM
RichardODreamweaver
 
Posts: n/a
Diggs:
Default Date formatting according to UTC timezones

Using MySQL, php

http://www.freecrm.x10hosting.com

Before setting up my tables, I need to better understand the relevance of the
datetime and conversion of this field.

I am based in th UK (UTC, Greenwich mean time), but my host is in the states,
which means that the "now" date and time is based on US time (UTC - ?)

I have done formatting of the date i.e. <?php echo date('D,
d/m/Y',strtotime($datetime['DATETIME'])); ?> but am not sure how to approach
the problem relative to the timezone of any visitor in the world.

I have a sniffer script which detects the browsers language but I can't see
that being of much use.

The site does require a register/login so I suppose I could have a UTC
preference (i.e. UTC + 3 or whatever) set into their record. This could then
be used something like this.

<?php echo date('D,
d/m/Y',strtotime($datetime['DATETIME']+$row_recordsetuser['UTCTIMEZONEPREFERENCE
']));?>

Does this make sense?

I know the formatting is going to be a challenge as well because the US uses
m/d/Y,

Or is there a way of formatting the MySQL data before its even called?

Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-12-2008, 01:31 PM
Michael Fesser
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

.oO(RichardODreamweaver)

>Using MySQL, php
>
> http://www.freecrm.x10hosting.com
>
> Before setting up my tables, I need to better understand the relevance of the
>datetime and conversion of this field.
>
> I am based in th UK (UTC, Greenwich mean time), but my host is in the states,
>which means that the "now" date and time is based on US time (UTC - ?)


Check date_default_timezone_set().

> I have done formatting of the date i.e. <?php echo date('D,
>d/m/Y',strtotime($datetime['DATETIME'])); ?> but am not sure how to approach
>the problem relative to the timezone of any visitor in the world.


You can only deal with your server's timezone setting.

> I have a sniffer script which detects the browsers language but I can't see
>that being of much use.


It's of absolutely no use. English and Spanish for example are spoken
all around the world, probably somewhere in almost every timezone.

> The site does require a register/login so I suppose I could have a UTC
>preference (i.e. UTC + 3 or whatever) set into their record.


Possible. If UTC/GMT is not enough, you could let the users choose the
offset themselves. This is how it's done in many popular forum scripts.

>This could then
>be used something like this.
>
> <?php echo date('D,
>d/m/Y',strtotime($datetime['DATETIME']+$row_recordsetuser['UTCTIMEZONEPREFERENCE
>']));?>
>
> Does this make sense?
>
> I know the formatting is going to be a challenge as well because the US uses
>m/d/Y,


YYYY-MM-DD

Works always. ;-)

> Or is there a way of formatting the MySQL data before its even called?


Of course you can also let MySQL return an already formatted date, which
is usually the preferred and most efficient way. Have a look at MySQL's
date and time functions, especially DATE_FORMAT().

Micha
Reply With Quote
  #3 (permalink)  
Old 06-19-2008, 07:56 PM
RichardODreamweaver
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

Thanks Micha - sorry for the late reply - I had some reading to do!

Apparently, the server datetime cannot itself be altered and the formatting
can only be changed during the MySQL call functions.

UTC_TIMESTAMP() recalls the server date and time in UTC format, which can then
be manipulated using the saved login preferences as you suggested.

I take it that this is more efficient than using php to convert after the data
has been called in a recordset.

I must admit, using YYYY-MM-DD H:i:s would be much simpler and easier to
manage but I'm unsure how many users accept this format - in the UK, it causes
many problems (even though it is the most logical string)

One thing that puzzles me though... I have used the phpBB3 forum functionality
(Brilliant!!) and, after checking the format of the dates and times, they are
all in VARCHAR with what looks like seconds - is this another system I'm not
aware of? I think UNIX_TIMESTAMP() works like this?

Rich

Reply With Quote
  #4 (permalink)  
Old 06-19-2008, 08:48 PM
RichardODreamweaver
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

OK, my server doesn't support UTC_TIMESTAMP!

Back to plan Z!

As an international format, would this be OK?

D, d M Y H:i:s

Wed, 19 Jan 2008 20:15:34
Reply With Quote
  #5 (permalink)  
Old 07-17-2008, 09:45 PM
RichardODreamweaver
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

OK - think I've sussed it.

All date fields will be in VARCHAR, using the Time() function to store as
UTC/GMT seconds.

The user can choose a preference for Timezone (e.g. GB, TCU, Etc/GMT+1)

Also, the user can select a time format which is strored.

On login, these preferences are stored as Session variables and used on each
page to set the timezone.

putenv ("TZ=".$_SESSION['timezone'])

All retrieved data can be expressed using the format preference ($utf):

echo date($utf, ($now))

Job done!

Reply With Quote
  #6 (permalink)  
Old 07-18-2008, 07:11 AM
Michael Fesser
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

.oO(RichardODreamweaver)

>OK - think I've sussed it.
>
> All date fields will be in VARCHAR, using the Time() function to store as
>UTC/GMT seconds.
>
> The user can choose a preference for Timezone (e.g. GB, TCU, Etc/GMT+1)
>
> Also, the user can select a time format which is strored.
>
> On login, these preferences are stored as Session variables and used on each
>page to set the timezone.
>
> putenv ("TZ=".$_SESSION['timezone'])


You should use date_default_timezone_set() instead:

| Note: Since PHP 5.1.0 (when the date/time functions were rewritten),
| every call to a date/time function will generate a E_NOTICE if the
| timezone isn't valid, and/or a E_STRICT message if using the system
| settings or the TZ environment variable.

http://www.php.net/manual/en/functio...mezone-set.php

Micha
Reply With Quote
  #7 (permalink)  
Old 07-18-2008, 04:24 PM
Gary White
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

On Fri, 18 Jul 2008 08:24:26 +0200, Michael Fesser <netizen@gmx.de>
wrote:

>You should use date_default_timezone_set() instead:


True if your PHP version is => 5.1. My approach is usually something
along the lines of:

function setTimeZone($z){
if(function_exists('date_default_timezone_set'))
date_default_timezone_set($z);
else
putenv("TZ=$z");
}

Gary
Reply With Quote
  #8 (permalink)  
Old 07-18-2008, 10:12 PM
RichardODreamweaver
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

[q]Originally posted by: Newsgroup User

You should use date_default_timezone_set() instead:
[/q]

Thanks Micha

Gary - as my server does support it, I'm not sure why I need the if function
exists code?



Reply With Quote
  #9 (permalink)  
Old 07-18-2008, 11:15 PM
Gary White
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

On Fri, 18 Jul 2008 22:04:55 +0000 (UTC), "RichardODreamweaver"
<webforumsuser@macromedia.com> wrote:

> Gary - as my server does support it, I'm not sure why I need the if function
>exists code?


It's just a safeguard. If the date_default_timezone_set() function is
supported, it is executed. On the other hand, if you later change
hosts and wind up with a server that does not support it, it won't
generate an error and fail. It will simply use the putenv() function
instead.

Gary
Reply With Quote
  #10 (permalink)  
Old 07-19-2008, 12:00 PM
Michael Fesser
 
Posts: n/a
Diggs:
Default Re: Date formatting according to UTC timezones

.oO(Gary White)

>On Fri, 18 Jul 2008 22:04:55 +0000 (UTC), "RichardODreamweaver"
><webforumsuser@macromedia.com> wrote:
>
>> Gary - as my server does support it, I'm not sure why I need the if function
>>exists code?

>
>It's just a safeguard. If the date_default_timezone_set() function is
>supported, it is executed. On the other hand, if you later change
>hosts and wind up with a server that does not support it, it won't
>generate an error and fail.


I don't think that this is very likely. Every good host should at least
support 5.1. Changing to another host should not become a "downgrade".

Anyway, another possible solution might be something like this:

if (!function_exists('date_default_timezone_set')) {
function date_default_timezone_set($z) {
putenv("TZ=$z");
}
}

I use a similar thing in my own scripts for the function str_getcsv().
It is already in the CVS, but not yet available in the stable releases.
But since I already want to use it, I simply use my own implementation
in a code block like above until the official version becomes available.

Micha
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 12:31 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk