dragon_sa Posted January 11, 2011 Share Posted January 11, 2011 Is there a way to put the value of every 15mins into an array starting and finishing at 2 var times $time1=10.00am $time2=1.30pm $timearray=array($time1, and every 15min interval up to but not including $time2) eg $timearray=array(10.00am,10.15am,10.30am..........1.15pm) Quote Link to comment https://forums.phpfreaks.com/topic/224071-put-every-15mins-into-array-from-between-2-times/ Share on other sites More sharing options...
denno020 Posted January 11, 2011 Share Posted January 11, 2011 get the system time using PHP - there are built in functions, like date, I think. Check if the time is between the times you want. Log data. To re-run the code, you might need a javascript timer set up that would refresh the page automatically every 15 minutes. But that's if you're using it in a website context.. and I'm not sure how you could be... Quote Link to comment https://forums.phpfreaks.com/topic/224071-put-every-15mins-into-array-from-between-2-times/#findComment-1157885 Share on other sites More sharing options...
dragon_sa Posted January 11, 2011 Author Share Posted January 11, 2011 I am wanting to echo the value of time every 15 minutes between the value of $time1 and $time2 comes from the database. Its for appointment bookings. I have converted them to timestamps using the date of the appointment and I have been trying to create a loop to add 900(15mins) to $time1 until it reaches $time2 but not had much success yet. Anyone have an idea how to run the loop to do this, the snag I having is $time1 and $time2 come from a while loop that pull the staff working times from a db on the booking date Quote Link to comment https://forums.phpfreaks.com/topic/224071-put-every-15mins-into-array-from-between-2-times/#findComment-1158021 Share on other sites More sharing options...
dragon_sa Posted January 12, 2011 Author Share Posted January 12, 2011 I have worked it out, I changed the times in my database to be 24hr times not 12 hour with am/pm the performed the following $sqlDATE=user input date from calendar select formated to yyyy-mm-dd $in="$sqlDATE 10.00:00"; // selected date + start time for staff member from database(24hr time) $out="$sqlDATE 18.00:00"; // selected date + finish time for staff member from database(24hr time) $in2=strtotime($in); // convert to timestamp $out2=strtotime($out); //convert to timestamp $stop=$out2-900; // 900 is 15 mins used to set last 15min appointment before staff finish // get the 15min variables in this case I am just echoing them for ($inc=$in2;$inc<=$stop;$inc=+900) { echo "Appointment time is ".date("g.i a", $inc)."<br/>"; // set back to readable time } Quote Link to comment https://forums.phpfreaks.com/topic/224071-put-every-15mins-into-array-from-between-2-times/#findComment-1158273 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.