Help with attempting to add time to a MySQL field from PHP?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bobmct

    Help with attempting to add time to a MySQL field from PHP?

    In my feeble attempt to keep track of login session timeouts I have the
    following code in my login section of my program:

    $sql = "UPDATE subscriber
    SET _sessexp = 'DATE_ADD(NOW() ,INTERVAL 15 MINUTES)'
    WHERE _userid = '$_userid'
    LIMIT 1";

    and when run I see NO ERRORS. However, either the field in the DB doesn't
    change OR this expression is generating a value of '0' for the _sessexp
    field.

    I've tried using the ADDTIME function as an alternative but get the same
    results. I'm kind of at a loss.

    Any ideas as to why this is NOT behaving as I expect it to?

    What I am attempting to do is to take the CURRENT TIME and add 15 minutes to
    it and update a field in the database record. That simple!

    Bob
  • Rik

    #2
    Re: Help with attempting to add time to a MySQL field from PHP?

    bobmct wrote:
    In my feeble attempt to keep track of login session timeouts I have
    the following code in my login section of my program:
    >
    $sql = "UPDATE subscriber
    SET _sessexp = 'DATE_ADD(NOW() ,INTERVAL 15 MINUTES)'
    WHERE _userid = '$_userid'
    LIMIT 1";
    >
    and when run I see NO ERRORS. However, either the field in the DB
    doesn't change OR this expression is generating a value of '0' for
    the _sessexp field.
    >
    I've tried using the ADDTIME function as an alternative but get the
    same results. I'm kind of at a loss.
    >
    Any ideas as to why this is NOT behaving as I expect it to?
    >
    What I am attempting to do is to take the CURRENT TIME and add 15
    minutes to it and update a field in the database record. That simple!
    First of all, you try to add the string 'DATE_ADD(NOW() ,INTERVAL 15
    MINUTES)' to a date field, which is invalid and will result to 0. Remove the
    quotes.
    Grtz,
    --
    Rik Wasmus


    Comment

    • bobmct

      #3
      Re: Help with attempting to add time to a MySQL field from PHP?

      Rik wrote:
      bobmct wrote:
      >In my feeble attempt to keep track of login session timeouts I have
      >the following code in my login section of my program:
      >>
      > $sql = "UPDATE subscriber
      > SET _sessexp = 'DATE_ADD(NOW() ,INTERVAL 15 MINUTES)'
      > WHERE _userid = '$_userid'
      > LIMIT 1";
      >>
      >and when run I see NO ERRORS. However, either the field in the DB
      >doesn't change OR this expression is generating a value of '0' for
      >the _sessexp field.
      >>
      >I've tried using the ADDTIME function as an alternative but get the
      >same results. I'm kind of at a loss.
      >>
      >Any ideas as to why this is NOT behaving as I expect it to?
      >>
      >What I am attempting to do is to take the CURRENT TIME and add 15
      >minutes to it and update a field in the database record. That simple!
      >
      First of all, you try to add the string 'DATE_ADD(NOW() ,INTERVAL 15
      MINUTES)' to a date field, which is invalid and will result to 0. Remove
      the quotes.
      Grtz,

      Well, OK;

      Already tried that first. With/without, single/double, doesn't seem to
      matter.

      Re-tried your suggestion and the result STILL results in ONLY ZERO in the
      field. However, can a time function's result be put into a bigint field?

      Bob

      Comment

      • Rik

        #4
        Re: Help with attempting to add time to a MySQL field from PHP?

        bobmct wrote:
        Rik wrote:
        >
        >bobmct wrote:
        >>In my feeble attempt to keep track of login session timeouts I have
        >>the following code in my login section of my program:
        >>>
        >> $sql = "UPDATE subscriber
        >> SET _sessexp = 'DATE_ADD(NOW() ,INTERVAL 15 MINUTES)'
        >> WHERE _userid = '$_userid'
        >> LIMIT 1";
        >>>
        >>and when run I see NO ERRORS. However, either the field in the DB
        >>doesn't change OR this expression is generating a value of '0' for
        >>the _sessexp field.
        >>>
        >>I've tried using the ADDTIME function as an alternative but get the
        >>same results. I'm kind of at a loss.
        >>>
        >>Any ideas as to why this is NOT behaving as I expect it to?
        >>>
        >>What I am attempting to do is to take the CURRENT TIME and add 15
        >>minutes to it and update a field in the database record. That
        >>simple!
        >>
        >First of all, you try to add the string 'DATE_ADD(NOW() ,INTERVAL 15
        >MINUTES)' to a date field, which is invalid and will result to 0.
        >Remove the quotes.
        >Grtz,
        >
        >
        Well, OK;
        >
        Already tried that first. With/without, single/double, doesn't seem
        to matter.
        Re-tried your suggestion and the result STILL results in ONLY ZERO in
        the field.
        DATE_ADD(NOW(), INTERVAL 15 MINUTE)

        NO 's' after MINUTE
        However, can a time function's result be put into a
        bigint field?
        I'm not sure what database you use, but in recent MySQL versions it will
        return a format of yyyy-mm-dd hh:mm:ss, not an integer.

        Do you by any chance mean UNIX_TIMESTAMP( DATE_ADD(NOW(), INTERVAL 15
        MINUTE))?

        Grtz,
        --
        Rik Wasmus


        Comment

        Working...