skip to Main Content

I am facing an issue in strtotime() in wordpress, that it is subtracting the hours according to my configured local timezone.

For example i tried strtotime("2021-11-16 00:00:00") on online php compiler it shows…

1637020800

but when i run the same on my wordpress site, var_dump(strtotime("2021-11-16 00:00:00")); it shows:

1637002800

which is wrong it is subtracting 5 hours as i set GMT+5 in my general settings.

I tried current_time(‘timestamp’) but it won’t help

Please can anyone help?

2

Answers


  1. Chosen as BEST ANSWER

    i found the problem in wordpress version 5.4.2, so basically in time zone if you select city,country it shows you this problem. While if you select like GMT +5 etc it will show correct.

    So i change Karachi to GMT+5 which make it sorted.


  2. Use this:

    function wp_strtotime($str) {
        return strtotime( wp_date( 'Y-m-d H:i:s', strtotime( $str ) ) );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search