Tuesday 24 June 2014

Get all dates in given month and year in php 0

To get all dates in given month and year, we need to know how many days in that given month and year.

to do that we are going to use PHP's date() and mktime() functions.

Syntax :

date(format,timestamp)
mktime(hour,minute,second,month,day,year,is_dst);

Function:

the following function will return dates in array format for given month and year in Y-m-d format.

Parameters:

$month   -  Month number
$year    -  Year        

usage:

$dates = get_dates($month,$year);

Example:
output:

Explanation:

We just calculated the number of days in month and using for loop, we are creating array in our own format.

Have any doubt, feel free to comment here!

0 comments:

Post a Comment