matleeds Posted March 22, 2012 Share Posted March 22, 2012 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)); Quote Link to comment https://forums.phpfreaks.com/topic/259478-how-to-only-use-date-not-time-in-a-calculation/ Share on other sites More sharing options...
litebearer Posted March 22, 2012 Share Posted March 22, 2012 What datatype is your is database field? Quote Link to comment https://forums.phpfreaks.com/topic/259478-how-to-only-use-date-not-time-in-a-calculation/#findComment-1330139 Share on other sites More sharing options...
matleeds Posted March 22, 2012 Author Share Posted March 22, 2012 it's unix datetime Quote Link to comment https://forums.phpfreaks.com/topic/259478-how-to-only-use-date-not-time-in-a-calculation/#findComment-1330140 Share on other sites More sharing options...
matleeds Posted March 22, 2012 Author Share Posted March 22, 2012 I'm wanting the next day but from midnight Quote Link to comment https://forums.phpfreaks.com/topic/259478-how-to-only-use-date-not-time-in-a-calculation/#findComment-1330141 Share on other sites More sharing options...
litebearer Posted March 22, 2012 Share Posted March 22, 2012 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/259478-how-to-only-use-date-not-time-in-a-calculation/#findComment-1330144 Share on other sites More sharing options...
freelance84 Posted March 22, 2012 Share Posted March 22, 2012 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/>'; Quote Link to comment https://forums.phpfreaks.com/topic/259478-how-to-only-use-date-not-time-in-a-calculation/#findComment-1330146 Share on other sites More sharing options...
matleeds Posted March 22, 2012 Author Share Posted March 22, 2012 thanks for the help and extensive coding there but my problem has been solved by one line and one function $tomorrow = strtotime("tomorrow"); returns the unix datetime for the next day from midnight....just what the doctor ordered Quote Link to comment https://forums.phpfreaks.com/topic/259478-how-to-only-use-date-not-time-in-a-calculation/#findComment-1330151 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.