Jump to content
Larry Ullman's Book Forums

Recommended Posts

I have a client who is a musician. I have set up a database that displays tour dates. This is done in WordPress, but the code is PHP, so I'm hoping someone here can help.

 

I've coded the page so that only dates that are equal to today or greater show up.

 

It all works fine, except the problem is a date falls off the page at 7:00PM my time (CST). I want it to stay until midnight.

 

I believe I am establishing today's date and then comparing it to a date entered in the database and telling the page to display any date that is equal or greater to today's date. Is there something I need to adjust somewhere that determines when the PHP code decides it is now the next day? As I said, it seems to be happening at 7:00PM and I need it to wait until midnight.

 

Any help would be greatly appreciated! Thanks!

 

The code looks like this:

 

 

$todaysdate = date("Ymd");

 

$args = array(

 

'meta_query' => array(

array(

'key' => 'TheDate',

'value' => $todaysdate,

'compare' => '>='

)

),

'cat' => '1',

'posts_per_page' => -1,

'orderby' => 'meta_value_num',

'meta_key' => 'TheDate',

'order' => 'ASC'

);

 

$the_query = new WP_Query( $args );

Link to comment
Share on other sites

This is a problem with timezones. I would recommend storing all dates and times using UTC and then convert to whatever time zone is appropriate. For example, shows in NY should be in EST/EDT but shows in LA should be in PST/PDT.

Link to comment
Share on other sites

Thanks for the input Larry. Unfortunately, it's not really practical in this case to enter in different time zones for each date. What I'd like to figure out is simply how to adjust the current setting. So, if all the dates right now drop off at 7:00PM CST, when I'm viewing them here in Central Time, where and what would I adjust to make them stay on until midnight CST? That would be close enough for my client. Thanks for the help.

Link to comment
Share on other sites

I would look at the DateTime class. The constructor allows you to specify a time and a timezone object. Specify the neutral London Timezone Object when inserting into the DB.

 

When you query for times, use DateTime::modify() or create an object with you timezone so it is correct.

 

That way it really doesn't matter what time zone you use. My two cents, but there as several ways.

Link to comment
Share on other sites

OK, so here's the deal. These "dates" are being entered through WordPress. I don't know how familiar any of you are with WordPress. We use a "custom field" to store the date. We use this syntax: "20120425" would be April 25, 2012. It appears that this is stored in the MySQL database as "longtext." We don't have any control over that.

 

Then I pull that value into the web page and compare it to a variable that establishes "today's date": $todaysdate = date("Ymd"); This allows me to then sort the dates in order.

 

I then say to display all dates that are greater than or equal to $todaysdate.

 

So, it's not really the individual dates that are entered into the database that I need to (or even can) deal with.

 

What I'm hoping I can do is figure out some way that the variable $todaysdate = date("Ymd"); lasts until midnight.

 

Right now it seems that at 7:00PM $todaysdate thinks it is now the next day.

 

I hope this makes sense. Thanks again for the help.

Link to comment
Share on other sites

I think you can try one of two things:

 

1. Check if you can specify a time zone in Wordpress. Pretty sure you can, as this is often a problem. (Maybe there's a plugin if it's not a default option)

 

2. Change the default timezone before creating $todaysdate

 

// Set timezone to london (neutral time)
date_default_timezone_set('Europa/London');

$todaysdate = date("Ymd");

Link to comment
Share on other sites

 Share

×
×
  • Create New...