Friday, March 23, 2007

Date and time manipulation in SQL

Date and time manipulation in SQL server 2000



---------------- Selecting only the date part from a datetime column --------------

/* Creating a Test Table */

Create Table MyDateTest99

(

datetime

)

go

/* Inserting the test value into the table */

insert into MyDateTest99 values (getdate())

go

/* Selecting the result */

select convert(varchar,DateColumn,108) from MyDateTest99

go

/* Performing Cleanup */

drop table MyDateTest99

go





Style ID

Style Type

0 or 100 mon dd yyyy hh:miAM (or PM)
101 mm/dd/yy
102 yy.mm.dd
103 dd/mm/yy
104 dd.mm.yy
105 dd-mm-yy
106 dd mon yy
107 Mon dd, yy
108 hh:mm:ss
9 or 109 mon dd yyyy hh:mi:ss:mmmAM (or PM)
110 mm-dd-yy
111 yy/mm/dd
112 yymmdd
13 or 113 dd mon yyyy hh:mm:ss:mmm(24h)
114 hh:mi:ss:mmm(24h)
20 or 120 yyyy-mm-dd hh:mi:ss(24h)
21 or 121 yyyy-mm-dd hh:mi:ss.mmm(24h)
126 yyyy-mm-dd Thh:mm:ss.mmm(no spaces)
130 dd mon yyyy hh:mi:ss:mmmAM
131 dd/mm/yy hh:mi:ss:mmmAM








powered by performancing firefox

No comments: