Posted By

aristoworks on 04/03/11


Tagged

month date number second week first third fourth


Versions (?)

Find The Number Of A Week In A Month For A Given Date


 / Published in: PHP
 

URL: http://www.aristoworks.com

This simple function allows you to find a weeks position in the month based on a given date. For instance I needed to alert the user their date was the "Second Week Of January" during a given month. I may never use it again but it came in very handy for this particular project.

  1. <?php
  2.  
  3. function week_number( $date = 'today' )
  4. {
  5. return ceil( date( 'j', strtotime( $date ) ) / 7 );
  6.  
  7. }
  8.  
  9. ?>
  10.  
  11. Usage Example:
  12.  
  13. <?php
  14.  
  15. $week_num = week_number();
  16.  
  17. $month = date("J", time());
  18.  
  19. echo "Today is the $week_num week of $month";
  20.  
  21. ?>

Report this snippet  

You need to login to post a comment.