Reputation: 397
I fetched into an array
the wp_posts
table in wordpress.
I want to make a cron job that would check if the post_date of each entry was one minute ago.
I tried this, but it doesn`t work.
foreach($arrayOfPosts as $post){
$postDate = strtotime($post['post_date']);
$formatedDate = strtotime($oneMinuteAgo);
$currentDate= strtotime(date("Y-m-d H:i:s"));
echo $postDate . "----" . $formatedDate . " <br/>";
if ($formatedDate <= $postDate){
array_push($arrayOfNewPosts,$post);
}
How should I do it?
Upvotes: 1
Views: 482
Reputation: 3928
just add to the post 60 seconds
and check if the timestamp is higher then the current time.
if the time is higher the post was posted within 1 minute.
$postDate = strtotime($post['post_date']);
if( ($postDate + 60) >= time() )
{
echo "within 1 minute";
}
Upvotes: 1
Reputation: 53228
Well, assuming that $postDate
contains what you think it does, the following code should be sufficient:
$postDate = strtotime($post['post_date']);
if($postDate == (time() - 60)
{
}
Please note that this checks if the post date is exactly one minute ago. To check for one minute or older, use $postDate <= (time() - 60)
.
Upvotes: 2
Reputation: 5090
Why would you need a $formatedDate ?
$postDate = strtotime($post['post_date']);
$currentDate= strtotime(date("Y-m-d H:i:s"));
if ($postDate < $currentDate - 60) {
}
Upvotes: 1