Jump to content

Darren_Stanley

New Members
  • Posts

    6
  • Joined

  • Last visited

Darren_Stanley's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have modified the IFELSE statement in order to debug to return $Line if <6. with an un-expected outcome. elseif($line<getNewLine()) { $weeks=($line+$noOfLines-getNewLine()); $modifier=$weeks.' weeks'; $rotaDate->modify($modifier); return $line;//$rotaDate ->format("jS F Y"); } Only the first line gets the $line number from the "if else" statement. The remaining lines less than 6, get the modified $rotaDate, each time this function is called.
  2. Unfortunately, this made no difference. I still have this problem.
  3. I have a working IF statement, but then when I add a 'ELSE IF' to this this 'overwrites' my IF. I will try to explain more here. For the purpose of this example, getNewLine() returns 6. $noOfLines = 58. $rotaDate = 5th Jan 2014 $line = from 1 to 58. My initial IF statement gives correct output (adding 1 week to each line):- //This function determines and inserts the custom column data. function customData($line){ global $rotaDate,$noOfLines; if($line >= getNewLine()){ $weeks=($line-getNewLine()); $modifier=$weeks.' weeks'; $rotaDate->modify($modifier); return $rotaDate ->format("jS F Y"); } 1 2 3 4 5 6 05-Jan-14 7 12-Jan-14 8 19-Jan-14 9 26-Jan-14 10 02-Feb-14 ... ... ... ... 56 21-Dec-14 57 28-Dec-14 58 04-Jan-15 So far, So good.. But now, I need to continue from 4-Jan line 58, back up to line 1, 1week later (11-Jan) down to line 5 of which would be 8th Feb. i.e. all lines Less than getNewLine() // which is 6 To do this I have added ELSE IF:- /* else if($line<getNewLine()) { $weeks=($line+$noOfLines-getNewLine()); $modifier=$weeks.' weeks'; $rotaDate->modify($modifier); return $rotaDate ->format("jS F Y"); } */ This the outputs from line 1 to line 5 correctly, But it continues to overwrite the dates down to line 58. It needs to stop at line 6. 1 11-Jan-15 2 18-Jan-15 3 25-Jan-15 4 01-Feb-15 5 08-Feb-15 6 15-Feb-15 7 22-Feb-15 8 01-Mar-15 9 08-Mar-15 10 15-Mar-15 11 22-Mar-15 ... ... ... ... down to line 58... Any ideas why this is happening and how I may stop this please?
  4. Kicken, Perfectly explained. My Problem solved.. Thanks Millions.
  5. OK, the Highlight didn't work in code. But the line in question, if you haven't already guessed. $rotaDate= new DateTime(); //returns a DateTime object
  6. HI, thanks for reading. Im am VERY NEW at PHP and coding, please don't get confused with the simplicity of my request.(maybe its just a syntax issue), but im not sure. First, I have set a variable: $rotaDate = date('5/1/14'); Then I have made a function. //This function determines and inserts the custom column data. function customData($line){ if($line==getNewLine()) { $rotaDate= new DateTime(); //returns a DateTime object return $rotaDate->format("jS F Y"); } else if($line>getNewLine()){ $weeks=($line-getNewLine()); $modifier=$weeks.' weeks'; $rotaDate = new DateTime(); //returns a DateTime object $rotaDate->modify($modifier); return $rotaDate ->format("jS F Y"); } } The line highlighted in RED, sets $rotaDate to Todays date as an object, but i don't want that. I need it to be an object date of MY $rotaDate = date('5/1/14') VARIABLE. The above code works, but outputs TODAYS DATE(as you would expect). any modification I make to this code creates an "not a date object" error. I think what I am trying to do is make my VARIABLE($rotaDate) an OBJECT. hope you can understand what Im trying to do. Thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.