[wp-testers] Date() function

Luke notfornoone at gmail.com
Mon Apr 19 08:07:58 UTC 2010


I have found that if you are on PHP5 doing the following seems to make
PHP's native date and time functions work as expected:

1. First set your timezone in Wordpress settings.
2. Then add something like the following:

function my_init() {
  if( get_option( 'timezone_string' ) != '' ) {
    date_default_timezone_set( get_option( 'timezone_string' ) );
  }
}
add_action( 'init', 'my_init');





On 19 April 2010 12:59, Chris Klosowski <chris at chriskdesigns.com> wrote:
> Whenever I try and run the PHP function date("Y-m-d") within my WordPress
> installation it appears to be modifying it by 1 day from the servers
> actually date("Y-m-d").
>
> The readout from a standard PHP file *outside* of WordPress is:
> 2010-4-18
> Which would trigger my plugin if it was within the WordPress environment.
>
> If I echo the date("Y-m-d") function *inside* of a WordPress file, my plugin
> file I get the date as:
> 2010-4-19
> Which does not allow my plugin to trigger.
>
> I've modified the Timezone in my WordPress settings to be my local timezone
> and no luck. Any thoughts?
>
> Chris K.
> chriskdesigns.com
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers
>


More information about the wp-testers mailing list