SQL Server/T-SQL/Date Timezone/Datetime
Converted to a datetime
1> create table employee(
2> ID int,
3> name nvarchar (10),
4> salary int,
5> start_date datetime,
6> city nvarchar (10),
7> region char (1))
8> GO
1>
2>
3> -- Converted to a datetime
4>
5> insert into employee (ID, name, salary, start_date, city, region)
6> values (1, "Jason", 40420, "02/01/94", "New York", "W")
7> GO
(1 rows affected)
1> insert into employee (ID, name, salary, start_date, city, region)
2> values (2, "Robert",14420, "01/02/95", "Vancouver","N")
3> GO
(1 rows affected)
1>
2> select * from employee
3> GO
ID name salary start_date city region
----------- ---------- ----------- ----------------------- ---------- ------
1 Jason 40420 1994-02-01 00:00:00.000 New York W
2 Robert 14420 1995-01-02 00:00:00.000 Vancouver N
(2 rows affected)
1>
2>
3>
4>
5> drop table employee
6> GO
DATETIME column
3> CREATE TABLE works_on (emp_no INTEGER NOT NULL,
4> project_no CHAR(4) NOT NULL,
5> job CHAR (15) NULL,
6> enter_date DATETIME NULL)
7> GO
1>
2> drop table works_on;
3> GO
Get Day only from a datetime variable
18>
19> CREATE FUNCTION DayOnly(@Date datetime)
20> RETURNS varchar(12)
21> WITH SCHEMABINDING
22> AS
23> BEGIN
24> RETURN CONVERT(varchar(12), @Date, 101)
25> END
26> GO
1> select dbo.DayOnly(GetDATE())
2> GO
------------
10/22/2006
(1 rows affected)
1> drop function DayOnly
2> GO
1>
2>