spires Posted May 24, 2007 Share Posted May 24, 2007 Hi I'm trying to find out how to find the 1st and the last day of the month, i'm using: $now = strtotime("Now"); to get todays day. I'm trying to build a listing section, Where users can select all from last month, this month ans next month. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/52773-1st-of-the-month/ Share on other sites More sharing options...
redarrow Posted May 24, 2007 Share Posted May 24, 2007 <?php $d_daysinmonth = date('t', mktime(0,0,0,$myMonth,1,$myYear)); // how many days in month $d_year = date('Y', mktime(0,0,0,$myMonth,1,$myYear)); // year $d_isleapyear = date('L', mktime(0,0,0,$myMonth,1,$myYear)); // is YYYY a leapyear? $d_firstdow = date('w', mktime(0,0,0,$myMonth,'1',$myYear)); // FIRST falls on what day of week (0-6) $d_firstname = date('l', mktime(0,0,0,$myMonth,'1',$myYear)); // FIRST falls on what day of week Full Name $d_month = date('n', mktime(0,0,0,$myMonth,28,$myYear)); // month of year (1-12) $d_monthname = date('F', mktime(0,0,0,$myMonth,28,$myYear)); // Month Long name (July) $d_month_previous = date('n', mktime(0,0,0,($myMonth-1),28,$myYear)); // PREVIOUS month of year (1-12) $d_monthname_previous = date('F', mktime(0,0,0,($myMonth-1),28,$myYear)); // PREVIOUS Month Long name (July) $d_month_next = date('n', mktime(0,0,0,($myMonth+1),28,$myYear)); // NEXT month of year (1-12) $d_monthname_next = date('F', mktime(0,0,0,($myMonth+1),28,$myYear)); // NEXT Month Long name (July) $d_year_previous = date('Y', mktime(0,0,0,$myMonth,28,($myYear-1))); // PREVIOUS year $d_year_next = date('Y', mktime(0,0,0,$myMonth,28,($myYear+1))); // NEXT year $d_weeksleft = (52 - $d_weekofyear); // how many weeks left in year $d_daysinyear = $d_isleapyear ? 366 : 365; // set correct days in year for leap years $d_daysleft = ($d_daysinyear - $d_dayofyear); // how many days left in year ?> Quote Link to comment https://forums.phpfreaks.com/topic/52773-1st-of-the-month/#findComment-260544 Share on other sites More sharing options...
spires Posted May 24, 2007 Author Share Posted May 24, 2007 WOW, Thats great, I'll try it all out. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/52773-1st-of-the-month/#findComment-260549 Share on other sites More sharing options...
spires Posted May 24, 2007 Author Share Posted May 24, 2007 Hi One other question: I'm using the code below to selct the 1st of next month, How do i make it so the month is in double figures? $myMonth = date('m', $day); $myYear = date('Y', $day); $d_month_next = date('n', mktime(0,0,0,($myMonth+1),28,$myYear)); $first_next = date('Y/'.$d_month_next.'/01'); echo $first_next; This prints out - 2007/6/01 I need it to print out 2007/06/01 Thanks once again Quote Link to comment https://forums.phpfreaks.com/topic/52773-1st-of-the-month/#findComment-260553 Share on other sites More sharing options...
redarrow Posted May 24, 2007 Share Posted May 24, 2007 http://uk3.php.net/date read this for date format ok. Quote Link to comment https://forums.phpfreaks.com/topic/52773-1st-of-the-month/#findComment-260555 Share on other sites More sharing options...
spires Posted May 24, 2007 Author Share Posted May 24, 2007 OK, Thanks once again. Quote Link to comment https://forums.phpfreaks.com/topic/52773-1st-of-the-month/#findComment-260556 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.