| Back to logs list
137867 2008 年 12 月 02 日 11:02 Reading (loading. ..) Comments (0) Category: Notes
1. the current system date and time
select getdate ()
2. dateadd added to the specified date,
new new balance shoes, based on a period of time to return the new datetime value
example: to date plus two days
select dateadd (day, 2, '2004-10- 15 ') - returns :2004-10-17 00:00:00.000
3. datediff returns across two date and time specified date the number of boundaries.
select datediff (day, '2004-09-01 ', '2004-09-18') - return: 17
4. datepart returns on behalf of the date specified in the specified date part of the integer.
select datepart (month, '2004-10-15 ') - returns 10
5. datename return date specified on behalf of some of the specified date string
select datename (weekday, '2004-10-15 ') - returns: Friday
6. day (), month (), year () - datepart comparison with what
select the current date = convert (varchar (10), getdate (),
new balance running shoes, 120),
current time = convert (varchar (8), getdate (), 114)
; select datename (dw, '2004-10-15 ')
select the number of weeks of this year s = datename (week, '2004-10-15 '),
today of the week = datename (weekday, '2004-10-15')
function
parameters / function GetDate ()
back to the system current date and time DateDiff (interval, date1, date2)
the interval specified manner,
交错 - Qzone日志, the return date2 and date1 between two dates difference date2-date1DateAdd (interval, number, date)
the interval specified manner, with number after the date of DatePart (interval, date)
date the return date, interval corresponding to the specified integer part DateName (interval, date)
date the return date, interval corresponding to specified parts of the string name of the parameter interval
settings are as follows:
value
abbreviation (Sql Server) (Access,
new balance 574, and ASP) Description Year
Yyyyyy in 1753 ~ 9999Quarter
Qqq quarter of 1 ~ 4Month
Mmm May 1 ~ 12Day of year
Dyy the number of days a year, the first few days of the year 1-366Day
Ddd ,1-31Weekday
Dww at the number of days a week,
new balance mens, the first few days of the week 1-7Week
Wkww week, the first few weeks of the year 0 ~ 51Hour
Hhh when 0 ~ 23Minute
Min min 0 ~ 59Second
Sss seconds 0 ~ 59Millisecond
Ms-ms 0 ~ 999
SQL Server Chinese version of the default The date field is datetime format yyyy-mm-dd Thh: mm: ss.mmm
example:
select getdate ()
2004-09-12 11:06:08.177
order a bit SQL Server which can often be used in the date format conversion method:
following examples:
select CONVERT (varchar, getdate (), 120)
2004-09-12 11:06:08
select replace (replace (replace (CONVERT (varchar, getdate (), 120 ),'-',''),'',''),':','')
20040912110608
select CONVERT ( varchar (12), getdate (), 111)
2004/09/12
select CONVERT (varchar (12), getdate (), 112)
20040912
select CONVERT (varchar (12) , getdate (), 102)
2004.09.12
select CONVERT (varchar (12), getdate (), 101)
09/12/2004
select CONVERT (varchar (12), getdate (), 103)
12/09/2004
select CONVERT (varchar (12),
Men must be strong - Qzone log, getdate (), 104)
12.09.2004
select CONVERT (varchar (12), getdate () , 105)
12-09-2004
select CONVERT (varchar (12), getdate (), 106)
12 09 2004
select CONVERT (varchar (12), getdate (),
new balance shoes, 107 )
09 12, 2004
select CONVERT (varchar (12), getdate (),
new balance sneakers, 108)
11:06:08
select CONVERT (varchar (12), getdate (), 109)
09 12 2004 1
select CONVERT (varchar (12), getdate (), 110)
09-12-2004
select CONVERT (varchar (12), getdate (),
Lonely - -!, 113)
12 09 2004 1
select CONVERT (varchar (12), getdate (), 114)
11:06:08.177