• Resolved dsdoyle

    (@dsdoyle)


    Hello,

    I have setup my functions.php page to change CSS files based on date. For example, today is Flag Day 6/14. I have the functions file enqueue a file named usa.css for the day and then the site is supposed to go back to the default CSS file (black) effective 6/15. It is currently 20:54 and the site (regardless of local staging or production copy) is using the default CSS even though it should be using the usa.css file for more than 3 hours more.

    Please advise.

    Thank you,

    Don

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Did you use a date function from plain PHP, or WP, or MySQL?
    The server has the time of where the server is located. When you choose a time in WP, that could be different from the server time.

    Thread Starter dsdoyle

    (@dsdoyle)

    I used (for example)

    switch (date(“Y-m-d”)){
    //Flag Day
    case date(“Y”).’-06-14′:
    $color = “usa”;
    break;
    }

    It does not matter if it is local on my laptop, staging or production

    Thread Starter dsdoyle

    (@dsdoyle)

    Hi,

    Any ideas?

    Thank you,

    Don

    So, you are using a plain PHP date(), which is the current time according to the timezone set, since you don’t pass in a timestamp. When WP starts, it sets the timezone to UTC. I’m not sure, but I think all dates are calculated off of that according to the timezone set in the General Settings (that options page temporarily sets the timezone to the one chosen to see if it’s Daylight Savings Time, but it sets it back to UTC).
    There were recent changes to the date functions in WP 5.3. A new function wp_date() was added which keeps the timezone separate.

    So to get the real date for your timezone, you would either set the timezone first (and set it back afterward), or ask WP for the date.

    Thread Starter dsdoyle

    (@dsdoyle)

    Hello,

    I just realized the issue as per your suggestion, I need to use Javascript to get the local machine’s date, create a cookie and push the data to PHP.

    Thank you,

    Don

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP not adhering to user time zone’ is closed to new replies.