Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2006, 04:22 AM
Authorized User
 
Join Date: Jan 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default now function help

Hi,

  how can we use function now(), it is used for current date.
Actually i want to add the current date in the query like this.
"insert into info id=8,date=".now()."name=name";

 
Old March 22nd, 2006, 08:06 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now() is an MySQL function, NOT a PHP function...

NOW() Returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context.

Try:
"INSERT INTO info ( id, date, name ) VALUES ( 8, NOW(), name );";


Links of interest:
    Date and Time Functions: http://dev.mysql.com/doc/refman/5.0/...functions.html
    PHP: date - Manual: http://www.php.net/date
    SQL Insert Into: http://www.w3schools.com/sql/sql_insert.asp

- A.Kahtava
 
Old March 30th, 2006, 02:06 AM
Authorized User
 
Join Date: Mar 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is also possible, using now()...

mysql> desc birth;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| uid | int(11) | YES | | NULL | |
| uname | varchar(30) | YES | | NULL | |
| bdate | date | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.03 sec)

mysql> insert into birth values
    -> (0,'z',now());
Query OK, 1 row affected (0.08 sec)

mysql> select * from birth where uid=0;
+------+-------+------------+
| uid | uname | bdate |
+------+-------+------------+
| 0 | z | 2006-03-30 |
+------+-------+------------+
1 row in set (0.05 sec)

Regards
Milind






Similar Threads
Thread Thread Starter Forum Replies Last Post
function keyvanjan ASP.NET 2.0 Professional 1 September 19th, 2007 10:22 AM
How to use Function akumarp2p SQL Server 2000 1 May 28th, 2007 05:04 AM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.