Jump to content

IAmBroom

Members
  • Posts

    5
  • Joined

  • Last visited

IAmBroom's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Thank you, sir. Your English was hard to parse... but I got the important part, and changed my code. It works now!
  2. I've stripped my code down to the bare basics, and it still is confusing me: <?php $str[] = "Bob"; echo $str.length;?> I expect an output of 1 but instead I get Arraylength WTF?Update: The non-standard function sizeof() works. This code: <?php $str[] = "Bob"; echo $str.length . "<br />"; echo sizeof($str) . "<br />"; var_dump($str) . "<br />";?> results in this output: Arraylength1array(1) { [0]=> string(3) "Bob" }
  3. IAmBroom

    Comparing Dates

    Another problem you have is that the DateTime::add() method will manipulate the actual date you're adding to.In the following line of code, both $dat1OffsetPeriodFromNow and $datCurr will have the same value. $dat1OffsetPeriodFromNow = $datCurr->add($intvlOffsetPeriod); You found it! Thanks!!! And... I promise to stick to one method. I just learned how to do all this last night... I'm a bit green!
  4. IAmBroom

    Comparing Dates

    So, the code below should be simple enough. I compare three dates: today (2/16/2014), a date just over a week from now (2/25/2014), and a date one month from now (3/16/2014). It should be Now < InOneWeek < OneMonthFromNow, but instead I bizarrely get the following output: Current Date = 2014-02-16 = 1392557618Event Date = 2014-02-28 = 1393 570800Offset Date = 2014-03-16 = 13949768182014-02-28 < 2014-02-162014-02-16 >= 2014-02-282014-02-28 < 2014-03-162014-03-16 >= 2014-02-28 I've highlighted the problem. Code follows; I can't see any reason why the date values should line up as 2/25/2014 < 2/16/2014 < 3/16/2014 <?php // Get the current date. // DateTime defaults to current time. $datCurr = new DateTime(); $strCurrDate = date_format($datCurr, "Y-m-d"); echo "Current Date = " . $strCurrDate . " = " . date_timestamp_get($datCurr) . "</br>"; // Convert the event date object to a string. $datEvent = new DateTime("Feb 28, 2014"); $strEventDate = date_format($datEvent, "Y-m-d"); echo "Event Date = " . $strEventDate . " = " . date_timestamp_get($datEvent) . "</br>"; // Sets an interval of 1 month. $intvlOffsetPeriod = new DateInterval('P1M'); $dat1OffsetPeriodFromNow = $datCurr->add($intvlOffsetPeriod); $str1OffsetPeriodFromNow = date_format($dat1OffsetPeriodFromNow, "Y-m-d"); echo "Offset Date = " . $str1OffsetPeriodFromNow . " = " . date_timestamp_get($dat1OffsetPeriodFromNow) . "</br>"; echo "</br>"; if ( date_timestamp_get($datEvent) < date_timestamp_get($datCurr) ) { echo "$strEventDate < $strCurrDate</br>"; } if ( date_timestamp_get($datEvent) >= date_timestamp_get($datCurr) ) { echo "$strEventDate >= $strCurrDate</br>"; } if ( date_timestamp_get($datCurr) < date_timestamp_get($datEvent) ) { echo "$strCurrDate < $strEventDate</br>"; } if ( date_timestamp_get($datCurr) >= date_timestamp_get($datEvent) ) { echo "$strCurrDate >= $strEventDate</br>"; } echo "</br>"; if ( date_timestamp_get($datEvent) < date_timestamp_get($dat1OffsetPeriodFromNow) ) { echo "$strEventDate < $str1OffsetPeriodFromNow</br>"; } if ( date_timestamp_get($datEvent) >= date_timestamp_get($dat1OffsetPeriodFromNow) ) { echo "$strEventDate >= $str1OffsetPeriodFromNow</br>"; } if ( date_timestamp_get($dat1OffsetPeriodFromNow) < date_timestamp_get($datEvent) ) { echo "$str1OffsetPeriodFromNow < $strEventDate</br>"; } if ( date_timestamp_get($dat1OffsetPeriodFromNow) >= date_timestamp_get($datEvent) ) { echo "$str1OffsetPeriodFromNow >= $strEventDate</br>"; }?> Help me, Obi Wan Kenobi - you're my only hope!
×
×
  • Create New...