note 107943 added to function.time

From: Date: Thu, 15 Mar 2012 18:29:26 +0000
Subject: note 107943 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-186694@lists.php.net to get a copy of this message
Something I often want to do is find out the first of the next month and to get the time() result for it. By using a combination of date() and strtotime(), you can do that: <?php // by: holdoffhunger@gmail.com // Example Time() Integer (for Thu, 15 Mar, 2012) $time_to_handle_for_next_month_conversion = 1331835943; // Date Conversions $interpretted_day = date('d', $time_to_handle_for_next_month_conversion); $interpretted_month = date('F', $time_to_handle_for_next_month_conversion); $interpretted_month_lowercased = strtolower($interpretted_month); $interpretted_year = date('Y', $time_to_handle_for_next_month_conversion); // Preset Day $new_day = 1; // Handle Case: December if($interpretted_month_lowercased == "december") { $new_month = "January"; $new_year = $interpretted_year + 1; } else { // Handle All Other Cases switch($interpretted_month_lowercased) { case 'january': $new_month = "February"; break; case 'february': $new_month = "March"; break; case 'march': $new_month = "April"; break; case 'april': $new_month = "May"; break; case 'may': $new_month = "June"; break; case 'june': $new_month = "July"; break; case 'july': $new_month = "August"; break; case 'august': $new_month = "September"; break; case 'september': $new_month = "October"; break; case 'october': $new_month = "November"; break; case 'november': $new_month = "December"; break; } $new_year = $interpretted_year; } $new_date_string = $new_day . " " . $new_month . " " . $new_year; // Results $first_day_of_the_next_month_time_integer = strtotime($new_date_string); // Result = 1333256400 (Sun, 1 Apr, 2012) ?> ---- Server IP: 69.147.83.197 Probable Submitter: 68.9.137.178 ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- https://master.php.net/note/edit/107943 Del: integrated -- https://master.php.net/note/delete/107943/integrated Del: useless -- https://master.php.net/note/delete/107943/useless Del: bad code -- https://master.php.net/note/delete/107943/bad+code Del: spam -- https://master.php.net/note/delete/107943/spam Del: non-english -- https://master.php.net/note/delete/107943/non-english Del: in docs -- https://master.php.net/note/delete/107943/in+docs Del: other reasons-- https://master.php.net/note/delete/107943 Reject -- https://master.php.net/note/reject/107943 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186694) next »