Processing form input as a date

Discussion in 'PHP' started by snigster, Apr 14, 2009.

  1. #1
    Hello,

    I am using the following code to take 15 minutes from the current date/time

    
    
    $minus = -900; 
    
    $nowtimeanddate = date("Y-m-d H:i:s");
    $nowtimeanddate15 = time($nowtimeanddate) + ($minus);
    $nowtimeanddate15 = date("Y-m-d H:i:s", $nowtimeanddate15);
    
    Code (markup):
    This works fine but I am trying to use the same thing to process a date submitted by a user but instead of getting changes made to the user's date, I get the time/date now plus/minus whatever variation I feed in.

    Anyone see what I'm doing wrong? Here's what I've got:

    
    $thisdate = $_POST['nojsyear']."-".$_POST['nojsmonth']."-".$_POST['nojsday'];
    $thistime = $_POST['stt_hour'].":".$_POST['stt_minute'].":".$_POST['stt_seconds'];
    
    $alltimedate = $thisdate." ".$thistime;
    $alltimedate = strtotime($alltimedate);
    $alltimedate = date("Y-m-d H:i:s", $alltimedate);
    $alltimedateUpdated = time($alltimedate) + ($minus);
    $alltimedateUpdated = date("Y-m-d H:i:s", $alltimedateUpdated);
    
    
    Code (markup):
    Any help will be greatly appreciated.
     
    snigster, Apr 14, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    why
    $alltimedateUpdated = date("Y-m-d H:i:s", $tweettimedateUpdated);
    Code (markup):
    shouldnt it be
    $alltimedateUpdated = date("Y-m-d H:i:s", $alltimedateUpdated );
    Code (markup):
     
    javaongsan, Apr 14, 2009 IP
  3. snigster

    snigster Peon

    Messages:
    88
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah, you're right. But that was a mistake in explaining the problem, in my actual code I have $alltimedateUpdated

    edit: for the purpose of clarity, I have corrected my original post
     
    snigster, Apr 14, 2009 IP
  4. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $minus = -900; 
    
    $nowtimeanddate = date("Y-m-d H:i:s");
    $nowtimeanddate15 = date("Y-m-d H:i:s", time() + $minus);
    Code (markup):
     
    SmallPotatoes, Apr 14, 2009 IP
  5. snigster

    snigster Peon

    Messages:
    88
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That is for the time and date now minus 15 minutes. I want to use a date stored in a variable rather thasn the time and date right now minus 15 mins. Make sense?
     
    snigster, Apr 15, 2009 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well, you can subtract 900 from any number you like.

    If your time is stored as a unix timestamp (integer) just subtract 900 from it.

    If it's stored in Y-m-d H:i:s, then strtotime it first.

    Maybe I am missing something which is making this more complicated than it seems to me.
     
    SmallPotatoes, Apr 15, 2009 IP