• Resolved mikeill

    (@mikeill)


    This seems to work, but I’d love input as wo whether or not it’s the right way to do it.

    strftime('%G', strtotime(date_i18n('Y-m-d')))

    Simply using date_i18n('Y') was working up until today, when it returned 2014 as opposed to 2015. And apparently we are in week 1 of 2015 according to UNIX? php?

    Thanks and Happy New Year.

Viewing 12 replies - 1 through 12 (of 12 total)
  • In WordPress, if you go to Settings > General, what is your timezone set to? Does it match the timezone you are in?

    Thread Starter mikeill

    (@mikeill)

    It’s set to Chicago for Central time, which is correct.

    I installed a clean version of WordPress, set my timezone to Chicago, and called this function:

    date_i18n('Y-m-d H:i:s');

    Which printed this:

    2014-12-29 14:08:45

    Based on this test, what used to work for you is still working here. I know my server’s timezone is set to GMT, so it is being converted properly by WordPress.

    The only time I’ve ever had issues with time in WordPress is when plugins try to overwrite the timezone, as some of them can manually call things like date_default_timezone_set, and depending on which order the plugins are loaded, have some sort of effect on that.

    Do you know if any plugins were recently updated? Would you be able to temporarily deactivate any plugins, just to see if it makes a difference?

    To answer your question, just using date_i18n is the way to go.

    Thread Starter mikeill

    (@mikeill)

    Thanks for your input, y the way, man. I get 2014 too, using date_i18n('Y') but am calling up a week using date_i18n("W", strtotime(date_i18n('Y-m-d'))), which returns 1, but this is week number 1 of 2015, not 2014.

    Ah, I see what you mean. So, in essence, everything is actually working as expected, because you’re asking WordPress/PHP two different questions.

    What year is it? 2014.

    What week are we in? 01.

    In never says that we are in week 1 of 2014, but you combined two answers from two different questions.

    Thread Starter mikeill

    (@mikeill)

    Yes. I’m looking at refactoring the whole thing because it’s quite messy trying to navigate back and forth between years. For example going from “week 1 in year 2015” to see what “last week” was (week final week in 2014 which is either 52 or 53 depending on the number of weeks that year had), etc.

    What I think I want to do now is just pass first date desired to view (as $_GET variable) and display the week based on that.

    Yes, passing a starting date is definitely a little less confining.

    With regard to using a $_GET variable, take a look at rewrite tags, rewrite rules, and the query_vars and post_link filter.

    Using some combination above, you can build elegant URL permalinks (or just work with queries a little easier) for a custom archive page like you’re describing.

    Thread Starter mikeill

    (@mikeill)

    Hmmm. I made a little demo plugin that just navigates through weeks, displaying the days of the week.

    Not sure how I would use rewrite tags or rewrite rules at the moment (it’s been a long day), but welcome suggestions.

    Ah, I see. For some reason I was thinking you were using this as an alternative way to browse a blog post archive. Instead of browsing by month, the user is browsing by week, hence my references above.

    Thread Starter mikeill

    (@mikeill)

    References appreciated nonetheless.

    If you feel that your initial inquiry has been addressed, go ahead and mark this thread as resolved. This will allow others to focus on helping with the unresolved cases.

    Thread Starter mikeill

    (@mikeill)

    Yes. Thanks for reminding me.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Correct way to Get Current year using date_i18n’ is closed to new replies.