Reputation: 87
I have tried to search it up, but it seems I can't find the correct answer.
Currently I am uploading the current time from one of my scripts after a first email is being send to companies, so after it has been send it will upload now()
to one of my tables in MySQL. This is uploading YYYY-MM-DD HH:MM:SS
Another script will resend a different email after five days with the partial script
if( $company_timestamp < strtotime('-5 days') && $email_sent == "NO" ){ /* Code */}
Where $company_timestamp
is the date and time told before.
It is indeed sending the email, but it seems it is not getting the correct time, because it is sending this email even after 5 seconds.
Is the format wrong of the date and time? And how can I make strotime()
work with my now()
in the database.
Upvotes: 0
Views: 973
Reputation: 703
You should define how strototime() should act. In your case you would have to define it this way:
date('Y-m-d H:i:s', strtotime('-5 days'));
as your variable $company_timestamp returns YYYY-MM-DD HH:ii:ss. Another option would be to transform your variable to "strtotime" date. So: strtotime($company_timestamp).
So your code would be in the first case:
if( $company_timestamp < date('Y-m-d H:i:s', strtotime('-5 days')) && $email_sent == "NO" ){
Upvotes: 3
Reputation: 1584
Your $company_timestamp
is a string, you need to convert it before you can compare it.
<?php
$email_sent = "NO";
$company_timestamp = date( 'Y-m-d H:i:s' );
if( strtotime( $company_timestamp ) < date( 'Y-m-d H:i:s', strtotime( '-5 days' ) ) && $email_sent == "NO" )
{
echo "Yes";
}
Upvotes: 0