christo16 Posted February 1, 2007 Share Posted February 1, 2007 Hello all, I am creating a timesheet application that will display a date such as Jan 1st 2007 to Jan 15th 2007. How do i code this in php to automatically to display each two week period (from saturday to saturday) based on what day it is? Such as today is the 31st so if the end of the pay period was on Friday Feb 2nd, the page would display Jan 19th to Feb 2nd. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/36597-creating-a-bi-weekly-calendar/ Share on other sites More sharing options...
dgiberson Posted February 1, 2007 Share Posted February 1, 2007 the way i did this was using an unixtimstamp and then adding to it... $today = time(); // 1209600 = # of seconds in a two week period $twoweeks_date = $today + 1209600; this will give you the date range you need, there are other ways to do this.... and it all depends on how you want to display your calendar, but at least this way you have your start & ending points btw, you will see posts that this method doesn't totally account for daylight savings, blah blah blah... which is true. however most of the time this will be sufficient. Quote Link to comment https://forums.phpfreaks.com/topic/36597-creating-a-bi-weekly-calendar/#findComment-174314 Share on other sites More sharing options...
christo16 Posted February 1, 2007 Author Share Posted February 1, 2007 Hey thanks that looks pretty good, but perhaps is there a way to do it in non unix timestamp or is there an easy way to convert it to english time? This is how i am displaying the calendar I will probably put above the calendar "Week Jan 1st- Jan 15th" Quote Link to comment https://forums.phpfreaks.com/topic/36597-creating-a-bi-weekly-calendar/#findComment-174323 Share on other sites More sharing options...
dgiberson Posted February 1, 2007 Share Posted February 1, 2007 use $print_date = strftime('%Y-%m-%d', $today) Quote Link to comment https://forums.phpfreaks.com/topic/36597-creating-a-bi-weekly-calendar/#findComment-174325 Share on other sites More sharing options...
chronister Posted February 1, 2007 Share Posted February 1, 2007 $timestamp=1169359200; echo date("m/d/y", $timestamp) will give you 01/21/07 The date function is pretty easy to use, and the unix timestamp is one of my favs to store date time and such. Quote Link to comment https://forums.phpfreaks.com/topic/36597-creating-a-bi-weekly-calendar/#findComment-174327 Share on other sites More sharing options...
dgiberson Posted February 1, 2007 Share Posted February 1, 2007 i have to echo chronister's comments, using unixtimestamps to do the work makes it much much easier to work with dates and times Quote Link to comment https://forums.phpfreaks.com/topic/36597-creating-a-bi-weekly-calendar/#findComment-174330 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.