SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    0 Post(s)
    0 Thread(s)

    Trying to decipher date-based code

    Hi all-

    I'm working on a calendar-based application and have been running into a glitch that I've tracked down to a block of code that I didn't write and therefore can't quite decipher. The application allows people to make selections each day of the calendar week, but they're not supposed to be able to change their selections two weeks from the current day. I've got a handle on the rest of the program, but I'm still somewhat (well, completely) fuzzy on date functions and so on - I've looked up much of it on, but am having trouble deciphering the following block of code, and was wondering if someone could explain it a little bit further to me-
    $datetemp = getdate();
    if ($_POST['eday'] && $month_num != $datetemp['mon']) {
    $eday = $_POST['eday'];
    $edayend = $_POST['edayend'];
    $edayend = $edayend-$eday;
    } else {
    $todaytemp = $datetemp['mday'];
    $weekdaytemp = $datetemp['wday'];
    if ( $weekdaytemp == 0) { $todaytemp +1; }
    $eday = $todaytemp+5;
    $edayend = $eday+5;
    while ($weekdaytemp > 1 ) {

    As far as I can tell, it's supposed to be able to differentiate between dates within the next two weeks, but there's still a lot that I can't make sense of - this is especially troublesome since this is the one part of the program that's causing serious errors. If someone could explain briefly to me exactly what this code does with the date, I would be extremely grateful.


  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Fairbanks, AK
    0 Post(s)
    0 Thread(s)
    Without seeing the full context of this block of code, I can't tell you much about it. Have you looked up the getdate() function in the PHP manual? That should at least get you moving in the right direction, telling you that e.g. $datetemp['wday'] is a numeric representation of the day of the week. The operations that this block of code runs through, however, are meaningless to those of us who don't know where the incoming variables come from (or at least what they're supposed to mean) not what the results are used for afterwards.

    At the very least give us the preconditions and postconditions for this block.


Posting Permissions

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