Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SybaseIQ-date function

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Getdate ()

Function:

Get the current time of the server

2. Datepart (interval,date)

Parameters:

Interval: a part of time (such as hours, minutes, seconds, days, weeks, months, seasons, years)

Date: current date or specified date

Function:

Take a certain part of a specified time, year, month, day, minute and second

Example:

Select datepart (yy,getdate ())-year

Select datepart (mm,'2012-05-01')-month

Select datepart (dd,getdate ())-day

Select datepart (hh,getdate ())-hour

Select datepart (mi,getdate ())-min

Select datepart (ss,getdate ())-sec

Select datepart (weekday,getdate ())-Sunday is the first day by default, which can be changed to Monday as the first day through set datefirst 1.

3. Datediff (interval,date,date)

Parameters:

Interval: a part of time (such as hours, minutes, seconds, days, weeks, months, seasons, years)

Date: current date or specified date

Function:

Calculate the difference between the first date and the second date after using the specified time part, the first is much more negative

Example:

Select datediff (day,'2008-10-1)-30

Select datediff (day,'2006-12-10)-10

4. Dateadd (interval, number, date)

Parameters:

Interval: interval time (such as hour, minute, second, day, week, month, quarter, year)

Number: interval (positive number is backward + N, negative number is forward-N)

Date: current date or specified date

Function:

Calculate the specified time, plus the length of time specified by the expression

Example:

Select dateadd (hour,1,getdate ())-time

Select dateadd (minute,1,getdate ())-points

Select dateadd (second,1,getdate ())-seconds

Select dateadd (day,1,getdate ())-days

Select dateadd (week,1,getdate ())-week

Select dateadd (month,1,getdate ())-month

Select dateadd (quarter,1,getdate ())-quarter

Select dateadd (year,1,getdate ())-year

5. Convert (type,date,style)

Parameters:

Type: the target data type to convert to (e.g. char, int)

Date: the date to be converted

Style: coding in the specified time / date format (e.g. 101,102)

Function:

Convert dates to other types and data in a specified format

Example:

Select convert (char,getdate (), 101)--'09 Universe 27 Universe 2003'

Select convert (char,getdate (), 102)-'2003.11.12'

Select convert (char,getdate (), 103)-- '27Universe 09Universe 2003'

Select convert (char,getdate (), 104)-'27.09.2003'

Select convert (char,getdate ()) -'27-09-2003'

Select convert (char,getdate (), 106) -'27 Sep 2003'

Select convert (char,getdate (), 107)-- 'Sep 27,2003'

Select convert (char,getdate (), 108)--'11 1615 06'

Select convert (char,getdate (), 109)-- 'Sep 27 2003 11 140 16 28 28 28 AM'

Select convert (char,getdate (), 110) -'09-27-2003'

Select convert (char,getdate (), 111)-- '2003 Universe 09exex27'

Select convert (char,getdate (), 112)-'20030927'

Select convert (char,getdate (), 120,120)-- '2012-05-01 14-14-21-14-40'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report