Home Sql SQL NOW() Function
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

SQL NOW() Function

Advertisement
NOW ( ) Function provides you the current date and time according to your computer's system date and time.

SQL NOW() Function

     

 

NOW ( ) Function provides you the current date and time according to your computer's system date and time. 

The SQL syntax for the Now ( ) function is:

Now ( )

The Now function returns a date and time that are stored in system.

Understand with Example

The Tutorial helps you to illustrate a example from SQL NOW( ) Function. In this Tutorial, we create a table 'Stu_Table' using create statement.

create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15), 
Stu_Class  varchar(10), sub_id varchar(2), marks varchar(3));

Insert Data into Stu_Table

The insert into statement is used to add records or rows into the table 'Stu_Table'.

SQL statement to insert data into table:

insert into Stu_Table values(1,'Komal',10,1,45);
insert into Stu_Table values(2,'Ajay',10,1,56);
insert into Stu_Table values(3,'Rakesh',10,1,67);
insert into Stu_Table values(1,'Komal',10,2,47);
insert into Stu_Table values(2,'Ajay',10,2,53);
insert into Stu_Table values(3,'Rakesh',10,2,57);
insert into Stu_Table values(1,'Komal',10,3,45);
insert into Stu_Table values(2,'Ajay',10,3,56);
insert into Stu_Table values(3,'Rakesh',10,3,67);
insert into Stu_Table values(1,'Komal',10,4,65);
insert into Stu_Table values(2,'Ajay',10,4,56);
insert into Stu_Table values(3,'Rakesh',10,4,37);
insert into Stu_Table values(1,'Komal',10,5,65);
insert into Stu_Table values(2,'Ajay',10,5,46);
insert into Stu_Table values(3,'Rakesh',10,5,63);

Stu_Table

Records in the table:

+--------+----------+-----------+--------+-------+
| Stu_Id | Stu_Name | Stu_Class | sub_id | marks |
+--------+----------+-----------+--------+-------+
| 1      | Komal    | 10        | 1      | 45    |
| 2      | Ajay     | 10        | 1      | 56    |
| 3      | Rakesh   | 10        | 1      | 67    |
| 1      | Komal    | 10        | 2      | 47    |
| 2      | Ajay     | 10        | 2      | 53    |
| 3      | Rakesh   | 10        | 2      | 57    |
| 1      | Komal    | 10        | 3      | 45    |
| 2      | Ajay     | 10        | 3      | 56    |
| 3      | Rakesh   | 10        | 3      | 67    |
| 1      | Komal    | 10        | 4      | 65    |
| 2      | Ajay     | 10        | 4      | 56    |
| 3      | Rakesh   | 10        | 4      | 37    |
| 1      | Komal    | 10        | 5      | 65    |
| 2      | Ajay     | 10        | 5      | 46    |
| 3      | Rakesh   | 10        | 5      | 63    |
+--------+----------+-----------+--------+-------+

Query

In this example, the use of Now function is used to returns the current date and time according to your computer's date and time. The Now( ) function return you the current date and time in double precision .

 

select stu_id, stu_name, GROUP_CONCAT(marks) as marks, 
sum(marks)as total ,avg(marks) as per, now()
from stu_table group by stu_id 

Result

+--------+----------+----------------+-------+------+---------------------+
| stu_id | stu_name | marks          | total | per  | now()               |
+--------+----------+----------------+-------+------+---------------------+
| 1      | Komal    | 45,65,47,65,45 | 267   | 53.4 | 2008-12-02 16:08:00 |
| 2      | Ajay     | 46,56,56,53,56 | 267   | 53.4 | 2008-12-02 16:08:00 |
| 3      | Rakesh   | 67,57,37,67,63 | 291   | 58.2 | 2008-12-02 16:08:00 |
+--------+----------+----------------+-------+------+---------------------+

Query

The Select now ( ) provide the current date and time.

Select now();

Result

+---------------------+
| now()               |
+---------------------+
| 2008-12-02 16:09:34 |
+---------------------+
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 20, 2008

Related Tutorials

Ask Questions?    Discuss: SQL NOW() Function  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
mehjabeen
January 30, 2013
how to use now() function

how to use now() function in oracle database 10g i am trying in my database but i am not get result
Sreekanth
March 10, 2012
NOW() not working

Hi In PL/SQL developer i tried with 2 sql quries. select now(); got alert as "FROM keyword not found where expected" select now() from dual; got alert as "NOW invalid identifier"
vishal pandey
April 30, 2012
question

Hi sir I AM VISHAL WHY USE database engine AND XML IN IT SECTOR
DMCA.com