Results 1 to 6 of 6

Thread: Date() Function Behaving strange... -[RESOLVEDish]-

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Resolved Date() Function Behaving strange... -[RESOLVEDish]-

    In my login file I have this code to add an entry to my login table.
    PHP Code:
    // Create an entry to the login table...
    $query "INSERT INTO `login` (`user_id`, `staff`, `guid`, `lastactive`) ";
    $query.= "VALUES (".$UserID.", 'no', '".$UserGUID."', '".date("Y-m-d H:i:s" ,time())."')";
    $results mysql_query($query); 
    When it is run and I see what the date/time was in the database I get:
    2000-11-00 44:68:93

    So I then Added in theses lines just after the above:
    PHP Code:
    $Date date("Y-m-d H:i:s" ,time());
    echo 
    "date(\"Y-m-d H:i:s\" ,time()) = $Date"
    The output and data in database was:
    2004-11-14 07:41:41

    So I then removed these two debug lines and the next time the entry to the database was:
    2000-11-00 44:70:74


    I can't understand how those two lines could possibly affect the SQL that is done before it .


    Update: I have tested this a few times since posting this and its the echo statement, if I take it out its the wrong time if I put it in its the right time, but I get errors later on cos I still have header info to send.
    Last edited by Electroman; Nov 14th, 2004 at 11:31 AM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    I would abandon use of the date() function, because all that can de done in MySql query:
    PHP Code:
    $query "INSERT INTO `login` (`user_id`, `staff`, `guid`, `lastactive`) ";
    $query.= "VALUES ('$UserID', 'no','$UserGUID',CURDATE());"
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    I thank you again Mr. Ad . BTW in SQl when I use the CURDATE() can I just add onto it like the php equivelant? I.E. if I do CURDATE()+60 that would be one minute?
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    That won't work unless you use a UNIX timestamp. You can use a UNIX timestamp, just set the field to an unsigned integer data type. In my opinion its easier if you are going to be doing arithmetic on the dates to use them, becuase you don't waste time and resources converting them.

    Here is what your query would look like:
    PHP Code:
    $query "INSERT INTO `login` (`user_id`, `staff`, `guid`, `lastactive`) ";
    $query.= "VALUES ('$UserID', 'no','$UserGUID',UNIX_TIMESTAMP() + 60);"
    You can also go down the route of using the MySql date add function, but again that mean un-necessary conversions. But just in case here are a list of all the date function in MySql:
    http://dev.mysql.com/doc/mysql/en/Da...functions.html


    Nice to see you using a real programming language. VB sux0r

    ** waits for a debate to start on whether or not PHP is a real programming lanauge **
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    ** waits for a debate to start on whether or not PHP is a real programming lanauge **
    We're in the PHP forum. Who would debate it?

    Different debate: why do you have a huge annoying text message in your sig?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Originally posted by CornedBee
    Different debate: why do you have a huge annoying text message in your sig?
    - I set the size wrong..

    Should have been 1, put 11 instead
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width