Jump to content

how to only use date not time in a calculation


matleeds

Recommended Posts

hi,

 

I have some code that deals with sending out reminders for appointments due the following day.

 

So if today is the 21/3 then only reminders for appointments due on the 22/3 should be sent.

 

Currently this isn't happening...

 

If reminders are sent on 21/3 at 9.50 am, my code adds 24 hours to this datetime and sends reminders due for all

appointments that fall bewteen 21/3 9.50am and 22/3 9.49 am.

 

What I want to do is simply send all reminders for appointments that are on the 22/3 exclusive of time.

 

I'm not sure how do this in php, which uses the unix datetime format to mildy complicate issues :)

 

anhy help or solutions would be massive, thanks.how to

 

 

$days = time() + (1 * (60 * 60 * 24));
$apts = $db->fetch_all('status = 1 AND time > ? AND time < ?', array(time(), $days));

Link to comment
Share on other sites

No first coffee yet, not tested  but maybe along these lines (Hopefully Pika will correct any errors I have)...

$tomorrow = date("Y-m-d", "+1 day");
$query = "SELECT whatever_fields FROM whatever_table WHERE DATE_FORMAT( `fieldname` , 'Y-m-d' )= '$tomorrow'";

Link to comment
Share on other sites

 

I've always wanted an excuse to play around with getting the correct timestamps for leading days.. here's one php way. I'm sure something is wrong with it and i'll get shot down...:

$localTimeAssoc = localtime(time(), true);

    $startDay = $localTimeAssoc[tm_mday] + 1;
    $endDayAgain = $localTimeAssoc[tm_mday] + 2;
    $thisMonth = $localTimeAssoc[tm_mon] + 1;
    $thisYear = $localTimeAssoc[tm_year] + 1900;

$timestampTonightAtMidnight = mktime(0,0,0,$thisMonth,$startDay,$thisYear);
$timestampTomorrowAtMidnight = mktime(0,0,0,$thisMonth,$endDayAgain,$thisYear);

echo $timestampTonightAtMidnight.'<br/>';
echo $timestampTomorrowAtMidnight.'<br/>';
echo '<br/>';
echo '<br/>';
echo date('d-m-Y:H-i-s',$timestampTonightAtMidnight).'<br/>';
echo date('d-m-Y:H-i-s',$timestampTomorrowAtMidnight).'<br/>';

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.