Calculators
|
|
|
|
<?php /*BEGIN FUNCTION*/
/*Returns an array with two timestamps, one for the start day of the month and
one for the end day. I expanded the month_end array's creation a little bit to make it easier to understand. I'm sure this has been done elsewhere but I couldn't find it when I looked.*/
function get_month_stamp($month, $year){
//Set month information
$month_end = array(
1 => 31,
2 => 28,
3 => 31,
4 => 30,
5 => 31,
6 => 30,
7 => 31,
8 => 31,
9 => 30,
10 => 31,
11 => 30,
12 => 31
);
//Select end day of month to work with
$end_day = $month_end[$month];
//Make time stamps
$start_stamp = mktime(0, 0, 0, $month, 1, $year);
$end_stamp = mktime(23, 59, 59, $month, $end_day, $year);
//Make array for return
$month_array = array('start'=>$start_stamp, 'end'=>$end_stamp);
Return $month_array;
} /*END FUNCTION*/ ?>
|
|
|
Usage Example
|
//Get the current month
$datearray = getdate();
$month = $datearray['mon'];
$year = $datearray['year'];
/*Use the function to get an array containing the two timestamps*/
$my_array = get_month_stamp($month, $year);
echo "Start: ".date("d/m/y", $my_array['start'])." | End: ".date("d/m/y", $my_array['end'])."<br />";
//And here are the timestamps
echo "Start Stamp: ".$my_array['start']." | End Stamp: ".my_array['end'];
|
|
|
Rate This Script
|
|
|
|