I’m having problems working through how I would build times that increment by a given multiple. I would like to have a function that would take 3 params, (start, end, offset) and that would give me an output:
The following function would take a start time of 0900, a stop time of 1200 and increment by multiples of 30 minutes.
Would someone please get me started in the right direction? I thought to use to mktime for this but I couldn’t get it to work.
myfunction(9, 12, 30)
output:
9:00 am
9:30 am
10:00 am
10:30 am
11:00 am
11:30 am
12:00 am
Function:
Output:
Codepad
strtotime is another useful function for dealing with dates and times in PHP.
The PHP Manual’s function reference is a great place to start when looking for how to do things yourself and taking advantage of built in functions. From that page if you do a search for ‘time’ you’ll find the Date/Time extension which is built in to PHP. You’ll see there are many functions available for dealing with date’s and time’s in PHP.