Results 1 to 6 of 6

Thread: really dumb date problem

  1. #1
    Join Date
    Jul 2010
    Birmingham, UK

    really dumb date problem

    I recently switched over to a new server, presumably in a completely different time zone from the last, and I am getting new users in different parts of the world now - both of which are leading me to discover this dumb new problem with my old date/time formats.

    Basically, and I'm sure I'm not the first to ask this, I'm trying to get the current time put into a format that reflects the user's local time - not my server's local time. My code as it is now looks like this: date('l, d F Y H:i:s T'), and the format itself is correct. The problem, of course, is that it is showing the time in PDT where the server is. Adding or subtracting from the timestamp only reflects the incorrect time in PDT and is not ideal anyway, and it seems that there must be a less messy way of giving the users local time using a straight-forward, standard PHP date/time function.

    I have looked through a list of the various functions in the PHP resources, but without fail I just get variations to the time in PDT. So I'm sort of scratching my head here a bit.

  2. #2
    Join Date
    Nov 2002
    Baltimore, Maryland
    The only dumb question is the one un-asked.

    If you are using PHP 5 and you know your user's time zone then see http://www.php.net/manual/en/functio...mezone-set.php . If you don't then you can use JavaScript. It won't work for a very large number of users but you can design around that so that it fails gracefully. But then your users already have the local time on screen, down on the lower, right corner. Double posting the time is more annoying than useful.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Jul 2010
    Birmingham, UK
    I suppose what I was asking - I'm sorry, I just thought I was clear there - is how to get my users' posts to read "Saturday, 06 August 2011 11:53:17 EDT" if they are in New York or whatever instead of "Saturday, 06 August 2011 08:53:17 PDT" where the server is located. I am really trying to avoid using Javascript in this case, but I just sort of thought that if I can get a user's IP and location using only PHP then perhaps there is a date function that can give me a correctly formatted date w/o jumping through a lot of hoops.

    This particular PHP file is running with PHP 4, so date_timezone_set doesn't seem like an option. The other problem with using Javascript, it seems, is that whenever I need to convert the date to another format (which happens now and again) I have to needlessly move over from PHP to Javascript and back again to avoid the same problem of the server's timezone getting used. Which is really, really messy.

  4. #4
    Join Date
    Mar 2011
    Ponca City, OK
    The best method in my opinion, and the one that I use is this:

    First all dates and times on my site are stored as a unix timestamp. Better then storing August 1st 2011 13:45 in the database and offers the most flexibility in displaying and manipulating dates.

    Second, on the server all times are stored based on the servers timezone. I make a note on my site that says what the default timezone is. I allow my users to select their timezone in their profile, which updates all the dates on the site to allow for their timezone offset. So all the guests see the server time and the logged in users see all the times based on their timezone. This allows for showing dates/times like, Yesterday, Today, x minutes ago, x hours ago, x days ago, all correctly based on the users current time.

    Hope this post helps you out.

  5. #5
    Join Date
    Nov 2002
    Baltimore, Maryland
    I'm thinking that you're just going to have to upgrade to PHP 5. Timezone rules are far more complicated than you realize, perhaps.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  6. #6
    Join Date
    Jul 2010
    Birmingham, UK


    Thanks to everyone for the input. I have a managed to solve the problem by creating a function that feeds the user's location to an outside api which in turn sends back the user's local time. I would normally want to keep it simple and work only with timestamps, but in this case it was important to keep the time in a format which included "PDT" or "EDT" or whatever... so that later on the time could be manipulated for other purposes to display the user's time of writing a message, etc. As I say, the problem with just storing away a timestamp is that when it is converted to a user-readable format it reflects the time where the server is, which just confuses people.

    Being stuck with php 4, in this case, sort of tied my hands a bit, but with the new function is place it all seems to work well - and it's all packaged up into a tidy function that limits the fuss. I'm still sort of amazed that this weird limitation exists, but it looks like the options in php 5 are worth exploring in the future if I'm going to have users in different parts of the world.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10177 seconds
  • Memory Usage 2,890KB
  • Queries Executed 15 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates