[PHP] Re: How to insert time and date into mysql?
The easiest way is to create a timestamp field (see manual depending on how you want to store the date, as you can go from to ddmmhhmmss...), and when you create your DB update query, use now(). for example, update a field with a new email address, and the user's current ip with the time of the update where his user id number is 123456789. UPDATE mail_address SET email = '$email', timesent = now(), ip = '$ip' WHERE user_id = 123456789; now() will set the value of the field timesent to the current time of the mysql server. Cheers, Daniel Zenith [EMAIL PROTECTED] a écrit dans le message news: 97jep3$sgu$[EMAIL PROTECTED] How can I insert time and date into mysql table, if the table i have to insert has a field of type time, and a field of type date. Then how can I insert it in PHP, if I use time() function?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: How to insert time and date into mysql?
Why not use the CURDATE() and CURTIME() functions built into mysql? Kevin Cawthorne - Original Message - From: "Foley, John" [EMAIL PROTECTED] To: "'Zenith'" [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, March 01, 2001 2:20 PM Subject: [PHP] RE: How to insert time and date into mysql? I have an application that serializes uploaded files by datetime of upload. This may not be the most efficient, but this will yield a MySQL DATETIME type string: $datetime = date("YmdHis"); If you are looking for a DATE column and a TIME column seperately (not recomended . . . use logic to parse the TIME and DATE parts of a DATETIME column) thet you will need to use $myDate = date("Ymd"); file://year,month,day with preceeding zeros $myTime = date("His"); file://hours,minutes,seconds with preceeding zeros I have not checked the documentation for these: check the DATE and TIME column type requirements in MySQL, and the date() function in PHP. Obviously, make sure your MySQL column data type is DATETIME, and that you single quote the $datetime value since it's considered text. Here is my SQL string: $sql="INSERT INTO $docMaster ( sqDocID, sqUID, sqSubmitDate, sqDocAnon, sqRequestID, sqHostID, sqTitle, sqCopies, sqOptionStr, sqFileName, sqDocType, Fsize, ppFsize ) VALUES( NULL, $uid, '$datetime', '$Anon', '$request_id', $sqHostID, '$title', $copies, '$option_list', '$file', '$DocType', $Fsize, $tmpFsize )"; It should be obvious by now that I am making a PHP4/CGI shell script LP print filter. This filter intercepts incoming print streams, then converts postscript to PDF or compresses PCL, moves the result to a controlled directory structure, and then logs to database. A little Apache with PHP with MySQL later, and I have a hands-off paperless queueing system. I love OpenSource! Any interest from the PHP community in seeing this effort released? I'm developing on Solaris for production use on Solaris, and have noted some incompatabilities with Linux, FWIW. John T. Foley Network Administrator Pollak Engineered Products, Actuator Products Division, A Stoneridge Company 195 Freeport Street, Boston MA 02122 ph: (617) 474-7266fax: (617) 282-9058 The geographical center of Boston is in Roxbury. Due north of the center we find the South End. This is not to be confused with South Boston which lies directly east from the South End. North of the South End is East Boston and southwest of East Boston is the North End. -Original Message- From: Zenith [SMTP:[EMAIL PROTECTED]] Sent: Monday, February 28, 2000 1:16 PM To: [EMAIL PROTECTED] Subject: How to insert time and date into mysql? How can I insert time and date into mysql table, if the table i have to insert has a field of type time, and a field of type date. Then how can I insert it in PHP, if I use time() function?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] RE: How to insert time and date into mysql?
Why not use the CURDATE() and CURTIME() functions built into mysql? Because my filing system requires that the filename.extension be datetime.extension in the PHP LP script (lazy man's serialization). That way, I can just referance the datetime when I build my table of links on the query output. Since this is an LP filter, there's no guarantee of consistancy in filenaming conventions in the LP/LPD handling from the clients. I've seen different behavior from Solaris (local queue) and the following client queues: HP-UX, IRIX 6.5, SAMBA, and most significantly OS/400. IRIX was the worst. I had to discover the "mkbsdnetpr" command since IRIX's graphical Printer Administrator makes for really strange queues. By default, there apparently is no LP style "host!user" information passed from an IRIX client to a "non-SGI" server. Instead, an option list "user@host; flist=file1 file2" is used. "mkbsdnetpr" however creates a "real" BSD-style queue. Also, since my main interest is in making paperless PCL reports from my AS/400 enterprise resource planning system, the filenames passed by OC/400's TCP/IP spooler are pretty meaningless anyway. (Ever seen what OS/400 does with filenames?) And, all, please disregard the file:// referances in my code examples from earlier. Damn Microsoft Outlook changed my C++ style comments without asking. John T. Foley Network Administrator Pollak Engineered Products, Actuator Products Division, A Stoneridge Company 195 Freeport Street, Boston MA 02122 ph: (617) 474-7266fax: (617) 282-9058 The geographical center of Boston is in Roxbury. Due north of the center we find the South End. This is not to be confused with South Boston which lies directly east from the South End. North of the South End is East Boston and southwest of East Boston is the North End. -Original Message- From: Kevin Cawthorne [SMTP:[EMAIL PROTECTED]] Sent: Thursday, March 01, 2001 9:58 AM To: Foley, John; 'Zenith'; [EMAIL PROTECTED] Subject: Re: [PHP] RE: How to insert time and date into mysql? Why not use the CURDATE() and CURTIME() functions built into mysql? Kevin Cawthorne - Original Message - From: "Foley, John" [EMAIL PROTECTED] To: "'Zenith'" [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, March 01, 2001 2:20 PM Subject: [PHP] RE: How to insert time and date into mysql? I have an application that serializes uploaded files by datetime of upload. This may not be the most efficient, but this will yield a MySQL DATETIME type string: $datetime = date("YmdHis"); If you are looking for a DATE column and a TIME column seperately (not recomended . . . use logic to parse the TIME and DATE parts of a DATETIME column) thet you will need to use $myDate = date("Ymd"); file://year,month,day with preceeding zeros $myTime = date("His"); file://hours,minutes,seconds with preceeding zeros I have not checked the documentation for these: check the DATE and TIME column type requirements in MySQL, and the date() function in PHP. Obviously, make sure your MySQL column data type is DATETIME, and that you single quote the $datetime value since it's considered text. Here is my SQL string: $sql="INSERT INTO $docMaster ( sqDocID, sqUID, sqSubmitDate, sqDocAnon, sqRequestID, sqHostID, sqTitle, sqCopies, sqOptionStr, sqFileName, sqDocType, Fsize, ppFsize ) VALUES( NULL, $uid, '$datetime', '$Anon', '$request_id', $sqHostID, '$title', $copies, '$option_list', '$file', '$DocType', $Fsize, $tmpFsize )"; It should be obvious by now that I am making a PHP4/CGI shell script LP print filter. This filter intercepts incoming print streams, then converts postscript to PDF or compresses PCL, moves the result to a controlled directory structure, and then logs to database. A little Apache with PHP with MySQL later, and I have a hands-off paperless queueing system. I love OpenSource! Any interest from the PHP community in seeing this effort released? I'm developing on Solaris for production use on Solaris, and have noted some incompatabilities with Linux, FWIW. John T. Foley Network