Search
 
SCRIPT & CODE EXAMPLE
 

SQL

timestamp datatype in sql

timestamp: Stores a unique number that gets updated every time a row gets created 
or modified. 
Comment

timestamp type in sql

SELECT GETDATE()    -- 2017-07-28 21:34:55.830
SELECT GETUTCDATE()     -- 2017-07-28 18:34:55.830
SELECT SYSDATETIME()        -- 2017-07-28 21:02:22.7446744
SELECT SYSUTCDATETIME()     -- 2017-07-28 18:20:27.5202777
SELECT SYSDATETIMEOFFSET()      -- 2017-07-28 21:02:22.7446744 +03:00
SELECT DAY(GETDATE())       -- 28
SELECT MONTH(GETDATE())     -- 7
SELECT YEAR(GETDATE())      -- 2017
SELECT DATENAME(month, GETDATE())       -- July
SELECT DATEADD(month, 2, '2017-7-28')       -- 2017-09-28 00:00:00.000
SELECT DATEADD(day, 5, '2017-7-28')     -- 2017-08-02 00:00:00.000
SELECT DATEADD(day, -5, '2017-7-28')        -- 2017-07-23 00:00:00.000
SELECT DATEDIFF(year, '2017-7-28', '2018-9-28')     -- разница 1 год
SELECT DATEDIFF(month, '2017-7-28', '2018-9-28')    -- разница 14 месяцев
SELECT DATEDIFF(day, '2017-7-28', '2018-9-28')      -- разница 427 дней
SELECT TODATETIMEOFFSET('2017-7-28 01:10:22', '+03:00')
SELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), '+02:30')
SELECT EOMONTH('2017-02-05')    -- 2017-02-28
SELECT EOMONTH('2017-02-05', 3) -- 2017-05-31
SELECT DATEFROMPARTS(2017, 7, 28)       -- 2017-07-28
SELECT ISDATE('2017-07-28')     -- 1
SELECT ISDATE('2017-28-07')     -- 0
SELECT ISDATE('28-07-2017')     -- 0
SELECT ISDATE('SQL')            -- 0
--Example:
CREATE TABLE Orders
(
    Id INT IDENTITY PRIMARY KEY,
    ProductId INT NOT NULL,
    CustomerId INT NOT NULL,
    CreatedAt DATE NOT NULL DEFAULT GETDATE(),
    ProductCount INT DEFAULT 1,
    Price MONEY NOT NULL
);
SELECT * FROM Orders
WHERE DATEDIFF(day, CreatedAt, GETDATE()) = 16
Comment

PREVIOUS NEXT
Code Example
Sql :: postgres insert 
Sql :: select sql 
Sql :: oracle multiple insert 
Sql :: rename command in sql 
Sql :: ORA-06502: PL/SQL: numeric or value error: character string buffer too small 
Sql :: where keyword sql 
Sql :: SQLSTATE[42S02]: Base table or view not found: 1146 Tabl 
Sql :: create view in oracle sql 
Sql :: postgresql functions 
Sql :: mariadb 
Sql :: ring MySQL commit updates to the database 
Sql :: UPDATE SQL RAHULDEV 
Sql :: sqlcmd xml output insert line break after every 2033 characters 
Sql :: how to check rollback status in oracle 
Sql :: ORACLE multiset union distinct 
Sql :: how to order result of subquery in select 
Sql :: psql fetch all rows with null 
Sql :: consulta alias con inner join 
Sql :: oracle single row functions 
Sql :: como leer datos de mysql esp32 
Sql :: sql multiple into 
Sql :: tornado_mysql 
Sql :: postgresql < ALL very slow 
Sql :: mysql missin expression near on 
Sql :: price-colour 
Sql :: odoo there is no primary key for referenced table "res_users" 
Sql :: Uncomment listen_address=localhost 
Sql :: mysql equivalent decode oracle 
Sql :: sql cmd no truncate 
Sql :: subquery aggregation 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =