473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

difference between now and sysdate

pradeepjain
563 Contributor
hi,
I got this definitions from mysql official site

now() - returns the current date and time.

SYSDATE() returns the time at which it executes

This differs from the behavior for NOW(), which returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW() returns the time at which the function or triggering statement began to execute.)

i did not get the actual meaning and when to use sysdate instead of now?
Mar 27 '10 #1
1 15835
Atli
5,058 Recognized Expert Expert
Hey.

Imagine having a stored procedure that inserts a billion rows into a table. Each row is supposed to have an identical time-stamp. The problem is that inserting a billion rows would take a lot of time.

If you use the SYSDATE() function, it would use the time when each individual INERT statement is executed, which means the rows would not have an identical time-stamp, because each statement is not executed at the same time.

To fix that, you can use the NOW() function. Instead of using the exact time when it is executed, it uses the time when the stored procedure was started, so the rows would all have the same time-stamp.

The example in the SYSDATE() manual entry explains this pretty well:
Expand|Select|Wrap|Line Numbers
  1. mysql> SELECT NOW(), SLEEP(2), NOW();
  2. +---------------------+----------+---------------------+
  3. | NOW()               | SLEEP(2) | NOW()               |
  4. +---------------------+----------+---------------------+
  5. | 2006-04-12 13:47:36 |        0 | 2006-04-12 13:47:36 |
  6. +---------------------+----------+---------------------+
  7.  
  8. mysql> SELECT SYSDATE(), SLEEP(2), SYSDATE();
  9. +---------------------+----------+---------------------+
  10. | SYSDATE()           | SLEEP(2) | SYSDATE()           |
  11. +---------------------+----------+---------------------+
  12. | 2006-04-12 13:47:44 |        0 | 2006-04-12 13:47:46 |
  13. +---------------------+----------+---------------------+
  14.  
In the top query, using the NOW() function, both return the same time even though they are executed two seconds a part. - In the bottom query, however, using the SYSDATE() function, they return the exact time when they are executed, two seconds a part.
Mar 27 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7336
by: WroteForLuck | last post by:
I am trying to write a simple SQL statement which will take a string (startdate) in the format DDMMYYYY and compare it to a date stored in an Oracle database. My SQL is as follows: <% "select * from tblhistory where datechanged = '" & startdate & "'" %>
1
3023
by: Yaroslav K. Kravchishin | last post by:
Oracle 7.0.1 Server When I type SQL> select sysdate from dual; SYSDATE --------- 01-OCT-03 01-OCT-03 2 rows selected.
0
758
by: Yaroslav K. Kravchishin | last post by:
Oracle 7.0.1 Server When I type SQL> select sysdate from dual; SYSDATE --------- 01-OCT-03 01-OCT-03 2 rows selected.
4
15725
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow which calculated the difference in years and days between two dates, and takes leap years into account? I'm calculating the difference in the usual way, i.e....
4
4503
by: sajan | last post by:
Hi, I new to python. I'm trying to make changes to an existing python code . The code has an if condition something like if datetime(*(time.strptime(creation_date, '%d-%b-%y'))) < datetime(2006,1,1):
5
4005
rsrinivasan
by: rsrinivasan | last post by:
Hi, When i Execute this query, I got the result as 29-MAY-07 select sysdate from dual; But i want 29-MAY-2007. What is the query for it? Thanks,
1
5760
by: sajithamol | last post by:
What is the difference between current_date & sysdate function?
12
2705
by: Petronius | last post by:
Hallo, does anyone have an idea how to implement difference lists in Javascript? Thanks allot in advance
3
3992
by: premkumarsp1 | last post by:
hi in the oracle sysdate, time is coming wrongly. THe date and time in the OS from where i am accessing oracle and in the OS where oracle is installed is correct. I want to know how to update time in sysdate. can someone help me with this problem.
1
3059
by: karuppiah | last post by:
Hi All, i need query,how to select last 3 month ,last 3wek,last 3 days , this last 3 month and 3 week should be friday, using sysdate from dual table, there is no exsting table, pls any one help me. Regards, karuppiah.
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.