SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot fredep57's Avatar
    Join Date
    Aug 2009
    Pacific Northwest
    0 Post(s)
    0 Thread(s)

    How to display end of month "rollover"

    OK, let me set up my issue.

    I have a mySQL database for events. In that database I have a starting date for the event and the duration of the event (default is, of course, 1 day). Now some events are more than 1 day and start on the last day of the month.

    So, my problem is how can I display the full duration of the event on my page appropriately? I have to account for the different months having different end dates - along with that pesky leap year.

    So, example is that I have an event that starts on March 30, 2012, and is 3 days long. How do I display it as "30-April 1" instead of using the easy way of just adding 3 to the start date (and subtract 1 for good measure) and having the display look like "30-32" which is, of course, incorrect?


  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    3 Post(s)
    0 Thread(s)
    Actually you can use it just like that , but if you want it formatted as 30 to April 1, you'll have to use some PHP logic to see if it's a new month.
    PHP Code:
    $start  mktime(0,0,0,1,30,2012); # will give you the timestamp for that day.
    $end mktime(0,0,0,1,32,2012); # will give you the time stamp for the 1st of feb. PHP does the rollovers for you automatically 
    So with this, you can use date(), to format it as you like.

    To check if it's a new month, you could do something simple like

    PHP Code:
    if (date('m'$start) != date('m'$end)) { # diff month } 


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts