~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/functions/current_time_functions.rst

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
mergeĀ lp:~olafvdspek/drizzle/refactor4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
CURRENT TIME FUNCTIONS
 
2
=======================
 
3
 
 
4
 
 
5
current_date
 
6
-------------
 
7
 
 
8
Returns the current date as a value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in a string or numeric context.
 
9
 
 
10
.. code-block:: mysql
 
11
 
 
12
        SELECT CURDATE();
 
13
                -> '2011-02-13'
 
14
        SELECT CURDATE() + 0;
 
15
                -> 20110213
 
16
 
 
17
current_time
 
18
--------------
 
19
 
 
20
Returns the current time as a value in 'HH:MM:SS' or HHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone.
 
21
 
 
22
.. code-block:: mysql
 
23
 
 
24
        SELECT CURTIME();
 
25
                -> '10:30:09'
 
26
        SELECT CURTIME() + 0;
 
27
                -> 103009.000000
 
28
 
 
29
 
 
30
current_timestamp
 
31
------------------
 
32
 
 
33
See :ref:`now`
 
34
 
 
35
CURRENT_TIMESTAMP() is a synonym for NOW(). 
 
36
 
 
37
localtime
 
38
-----------
 
39
 
 
40
See :ref:`now`
 
41
 
 
42
LOCALTIME() is a synonym for NOW(). 
 
43
 
 
44
localtimestamp                     
 
45
---------------
 
46
 
 
47
See :ref:`now`
 
48
 
 
49
LOCALTIMESTAMP() is a synonym for NOW(). 
 
50
 
 
51
.. _now:
 
52
 
 
53
now()                               
 
54
------
 
55
 
 
56
NOW returns the current date and time. The return value will be expressed as 'YYYY-MM-DD HH:MM:SS:mmmmmm' or YYYYMMDDHHMMSS.uuuuuu, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone.
 
57
 
 
58
.. code-block:: mysql
 
59
 
 
60
        SELECT NOW();
 
61
                -> '2011-02-15 13:40:06:002203'
 
62
        SELECT NOW() + 0;
 
63
                -> 20110215134006.002203
 
64
 
 
65
NOW returns a constant time that indicates the time at which the statement began to execute. 
 
66
 
 
67
.. code-block:: mysql
 
68
 
 
69
        SELECT NOW(), SLEEP(2), NOW();
 
70
 
 
71
Returns:
 
72
 
 
73
+----------------------------+----------+----------------------------+
 
74
| NOW()                      | SLEEP(2) | NOW()                      |
 
75
+============================+==========+============================+
 
76
| 2011-02-20 20:15:09:002203 |        0 | 2011-02-20 20:15:09:002203 |
 
77
+----------------------------+----------+----------------------------+
 
78
 
 
79
SYSDATE, however, returns the exact time at which the function was invoked.
 
80
 
 
81
.. code-block:: mysql
 
82
 
 
83
        SELECT SYSDATE(), SLEEP(2), SYSDATE();
 
84
 
 
85
Returns:
 
86
 
 
87
+---------------------+----------+---------------------+
 
88
| SYSDATE()           | SLEEP(2) | SYSDATE()           |
 
89
+=====================+==========+=====================+
 
90
| 2011-02-20 20:15:09 |        0 | 2011-02-20 20:15:11 |
 
91
+---------------------+----------+---------------------+
 
92
 
 
93
When using replication, the binary log will include SET TIMESTAMP entries so that a database can be restored from the binary log. In doing this, values from NOW will be adjusted to the same times as when the original SQL statements were executed. SYSDATE entries will be unaffected by SET TIMESTAMP entries.
 
94