Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 22nd, 2006, 04:22 AM
Authorized User
 
Join Date: Jan 2006
Location: lahore, punjab, Pakistan.
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";

Reply With Quote
  #2 (permalink)  
Old March 22nd, 2006, 08:06 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
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
Reply With Quote
  #3 (permalink)  
Old March 30th, 2006, 02:06 AM
Authorized User
 
Join Date: Mar 2006
Location: , , India.
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:45 AM.


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