CAST(OrderDate AS varchar) : datetime « Data Types « SQL Server / T-SQL Tutorial






3>
4> CREATE TABLE Orders (
5>      OrderID int NOT NULL ,
6>      CustomerID nchar (5) NULL ,
7>      EmployeeID int NULL ,
8>      OrderDate datetime NULL ,
9>      RequiredDate datetime NULL ,
10>     ShippedDate datetime NULL ,
11>     ShipVia int NULL ,
12>     Freight money NULL DEFAULT (0),
13>     ShipName nvarchar (40) NULL ,
14>     ShipAddress nvarchar (60) NULL ,
15>     ShipCity nvarchar (15) NULL ,
16>     ShipRegion nvarchar (15) NULL ,
17>     ShipPostalCode nvarchar (10) NULL ,
18>     ShipCountry nvarchar (15) NULL
19> )
20> GO
1>    SELECT OrderDate, CAST(OrderDate AS varchar) AS "Converted"
2>    FROM Orders
3>    WHERE OrderID = 11050
4> GO
OrderDate               Converted
----------------------- ------------------------------

(0 rows affected)
1>
2> drop table orders;
3> GO
1>








5.9.datetime
5.9.1.datetime type
5.9.2.Store the date and time for a change in a datetime format.
5.9.3.Billings on or before a specified date
5.9.4.A BETWEEN phrase with literal values
5.9.5.Using comperison operator with Date value
5.9.6.Between date
5.9.7.SET start_Date = GETDATE()
5.9.8.Use 'LIKE pattern' match with a date type value
5.9.9.An UPDATE statement that assigns new values to datetime column with string value
5.9.10.CAST(OrderDate AS varchar)
5.9.11.Specify date with string (OrderDate = '7/4/1996')
5.9.12.Performing Date Conversions
5.9.13.SELECT CONVERT(datetime, CONVERT( varchar(11), '2005-08-13 20:37:22.570', 101))
5.9.14.Add integer and float number to a date value
5.9.15.A SELECT statement that ignores date values
5.9.16.A SELECT statement that uses the CONVERT function to remove time values
5.9.17.A SELECT statement that uses the CAST function to remove time values
5.9.18.A SELECT statement that searches for month, day, and year components