I am trying to convert a string to a timestamp but it is just not happening. This has gone above my expertise and from my googling, it looks like I shouldn't be seeing what I am seeing so I am thinking there is a bigger problem I am missing.
I am getting a date string from a WordPress function and then trying to use PHP to convert it. All I want from the string is the Month and Day (eg Mar 07) but I am failing to get anything date related:
error_reporting(-1);
$my_post_date = '{{ post_data:post_date_gmt }}';
echo $my_post_date; // Result: 2017-03-07 01:35:43
var_dump($my_post_date); // Result: string(29) "2017-03-07 01:35:43"
$timestamp = strtotime($my_post_date);
var_dump($timestamp); //Result: bool(false)
I can't understand why that date string is breaking strtotime().
I have debugging on and there is no error_log so I can't see any errors.
UPDATE: The following has potentially identified the issue but it still has me confused...
var_dump(substr($my_post_date, 0, 3)); // Returns: string(3) "{{ "
It would seem your dumps/echos have their contents substituted after printing.
Proof of this is that 2017-03-07 01:35:43
is only 19 characters long but the vardump gives "str(29)". So what you're feeding strtodate is {{ post_data:post_date_gmt }}
Which it obviously wouldn't recognise.
So Wordpress performs the substitution at a later point during the execution
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.