How Many Weeks Between Dates?
The idea for this article and its accompanying software was triggered by the thought of an important Possibilities ezine anniversary that is coming up.
Because Possibilities is published every week, the software calculates the number of weeks between two dates.
My thought is that knowing the number of weeks may be helpful for other things, too. Anything that is measured in weeks might be a candidate.
A year has more days than just 52 weeks worth. Did you know that? It affects calculations when the period is a number of years.
Every year, there are 52 weeks plus 1 day. On leap years, there are 52 weeks plus 2 days.
So, every 5 or 6 years you get an extra week.
A working installation is available. See the How Many Weeks Between Dates? demo.
The source code is below. Copy it and save it with a .php
file name. Upload it to your server and types its URL into your browser's address bar.
<?php /* How Many Weeks Between Dates? Version 1.0 July 8, 2024 Will Bontrager Software LLC https://www.willmaster.com/ */ ?><!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>How Many Weeks?</title> <style type="text/css"> body { font-size:100%; font-family:sans-serif; background-color:white; } a { text-decoration:none; } </style> </head> <body> <h1 style="text-align:center;"> <a href="https://www.willmaster.com/"> <img src="https://www.willmaster.com/images/wmlogo_icon.gif" alt="Willmaster logo"> </a> How Many<br>Weeks Between Dates? </h1> <form id="my-form" action="<?php echo($_SERVER['PHP_SELF']) ?>" method="post"> <div style="display:table; margin:0 auto;"> <div style=text-align:right;"> From date: <input type="date" name="fromdate"><br> To date: <input type="date" name="todate"> </div> <p style="text-align:center;"> <input type="submit" name="submitter" value="Calculate It"> </p> </div> </form> <div style="display:table; margin:0 auto; border:1px solid #999; border-radius:.5em; padding:.75em;"> <?php if( isset($_POST['submitter']) ) { $today = date('Y-m-d'); if( ! preg_match('/\d/',$_POST['fromdate']) ) { $_POST['fromdate'] = $today; } if( ! preg_match('/\d/',$_POST['todate']) ) { $_POST['todate'] = $today; } $date1=mktime(0,0,0,intval(substr($_POST['fromdate'],5,2)),intval(substr($_POST['fromdate'],-2)),intval(substr($_POST['fromdate'],0,4))); $date2=mktime(0,0,0,intval(substr($_POST['todate'],5,2)),intval(substr($_POST['todate'],-2)),intval(substr($_POST['todate'],0,4))); $diff = abs($date2-$date1) / (60*60*24); $wks = $diff/7; $int = intval($wks); echo "Results:<br>Number of days is $diff<br>Number of weeks is $wks<br>Number of whole weeks is $int"; } else { echo '[Results of calculation will be here.]'; } ?> </div> <p style="text-align:center;"> © 2024 <a href="https://www.willmaster.com/">Will Bontrager Software LLC</a> </body> </html>
To test the demo or your installation of the software, the Possibilities ezine's publication length can be calculated.
Enter July 27, 1999 as the first date. And July 27, 2024 as the second date. The result will be the number of weeks in 25 years. The number of weeks is also the ezine's 25th anniversary issue number.
If you get the answer "Number of whole weeks is 1304", your installation of the software does the calculations correctly.
(This content first appeared in Possibilities newsletter.)
Will Bontrager