Jump to content

date time problem


corbeeresearch

Recommended Posts

Hi,

 

I'm preparing a code for an automated email, but the date time is not working correctly. I wanted to do a cron scheduler that emails people twice a day - 9am and 9pm. 9am sends email about records logged starting 9pm yesterday to 9am, while 9pm sends email about records logged from 9:01am to 9:00pm. The database uses date/time, so I was doing an if statement of date time, but I wasn't getting the result I wanted.

 

Sometimes the $now time is not within the yesterday 9pm to the 9pm today range. I don't know what I'm doing wrong, but I'm sure that it has something to do with the if statement, as the some of the $now time enters the else statement

 

Here is my code:

 

<?php
$today = date('Y-m-d 00:00:00');
$nineyesterday = date('Y-m-d H:i:s', mktime(date("H") - (date("H") + 6), date("i") - date("i"), date("s") - date("s"), date("m") , date("d"), date("Y")));
$now = date('Y-m-d H:i:s', mktime(date("H") + 13, date("i"), date("s"), date("m") , date("d"), date("Y")));
$nineam = date('Y-m-d 09:00:00');
$nine30 = date('Y-m-d 09:30:00');
$ninepm = date('Y-m-d 18:00:00');
echo '9pm yesterday: '.$nineyesterday;
echo '<br/>';
echo '9am: '.$nineam;
echo '<br/>';
echo '9pm: '.$ninepm;
echo '<br/>';
echo 'now: '.$now;
echo '<br/>';


if ((strtotime($now) > strtotime($nineyesterday)) and  (strtotime($now) <= strtotime($nineam)))
{
//count the answers by yes or no
echo 'am';

}
elseif ((strtotime($now) > strtotime($nineam)) and  (strtotime($now) <= strtotime($ninepm)))
{
//count the answers by yes or no
echo 'pm';
}
else
{
echo 'error';
}
?>

 

Thanks in advance

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.