. The value of interval is as follows: SQL Server (access and Asp) DescriptionYear YY yyyy-1753 ~ 9999Quarter qq q quarter 1 ~ 4Month mm m Month 1 ~ 12Day of year dy y the number of days of the year, the day of the year 1-366Day dd d, 1-31Weekday DW w the number of days in a week, the day of the week 1-7Week wk WW week, the week of the year 0 ~ 51Hour hh h 0 ~ 23Minute MI n minutes 0 ~ 59Second ss s 0 ~ 59Millisecond MS-millisecond 0 ~ 999 Access
SQL statement gets a specific date
1. The first day of one months
Select DATEADD (mm, DATEDIFF (Mm,0,getdate ()), 0)
2. Monday of this week
Select DATEADD (wk, DATEDIFF (Wk,0,getdate ()), 0)
3. The first day of the year
Select DATEADD (yy, DATEDIFF (Yy,0,getdate ()), 0)
4. First day of the quarter
Select DATEADD (QQ, DATEDIFF (Qq,0,getdate ()), 0)
5. The middle of the day
Select DATEADD (DD, DAT
leverage the existing datetime manipulation functions in SQL Server. This article provides helper functions to convert between the two representations. In total there are five user defined functions.Name Description fn_AgentDate2DateTime Converts an SQL Agent integer date r
Select A.user_name,Decode (A.sex, 1, ' Male ', 2, ' female ') as SEX,A.head_portrait,TRUNC (Months_between (sysdate, A.birthday)/12) | | ' Old ' as BIRTHDAY,Z.disease_nameFrom T_patient_info ADescription: Decode numeric match field, write to SQL will not have to go to the page Months_between gets the number of months between two time intervals, here is the divisible 12来 gets the age, is very convenient,The trunc function returns a
1. Date and time functions in SQL Server1. Current system date, timeSelect GETDATE ()2. DateAdd returns a new datetime value based on adding a period of time to the specified dateExample: Add 2 days to the dateSelect DATEADD (day,2, ' 2004-10-15 ')--return: 2004-10-17 00:00:00.0003. DateDiff returns the number of
Label:One, Time function When you use stored procedures, SQL functions, you encounter some processing of time. such as the acquisition of time and the addition and subtraction. In this case, the SQL comes with the time function. Below I list these functions, easy to remember later, use. --getdate Get current time
Sele
Interval helps you easily understand my different date calculation examples.
The first day of a month
In the first example, I will show you how to get to the last day of the month from the current date. Note: This example and other examples in this article will only use the datediff and dateadd functions to calculate the
Tags: calculate high-precision modified address EFI struct arithmetic uname table structureSQL queries and SQL functions This chapter aims Understanding Oracle Data Types Understanding Data Definition Languages and data manipulation languages Understanding Transaction Control Languages and Data Control languages Mastering SQL Operators and
Tags: cat when color sub har data sha Col sql Pay attention to MM,DD,MO,TU, etc. Hive can use case when in the Where condition
Known Date
Requested date
Statement
Results
Any day of the week
Monday
Select Date_sub (Next_day (' 2016-11-29 ', ' MO '), 7);
2016-11-28
Any day of the week
Datediff,dateadd,datepart is also used toIn Access and ASP, the use of these functions is similarExample:1.GetDate () for SQL Server:select GetDate ()2.DateDiff (' s ', ' 2005-07-20 ', ' 2005-7-25 22:56:32 ') returns a value of 514,592 secondsDateDiff (' d ', ' 2005-07-20 ', ' 2005-7-25 22:56:32 ') returns a value of 5 days3.DatePart (' W ', ' 2005-7-25 22:56:32 ') returns a value of 2 that is Monday (Sund
article will only use the datediff and dateadd functions to calculate the date we want. In each example, the date to be calculated is obtained through calculation but the previous time interval, and then addition or subtraction is performed. This is the SQL script used to calculate the first day of a month:Select d
SQL Server date calculation
SQL Server date calculation
SQL Server date calculation
Generally, you need to obtain the current date and calculate some other dates. For example, your pro
SQL Server date calculation methods (favorites)
SQL Server date calculation methods (favorites)
Generally, you need to obtain the current date and calculate some other dates. For example, your program may need to determine the first or last day of a month. Most of you proba
current date to the last day of the month. Please note: This example and the other examples in this article will only use the DateDiff and DATEADD functions to calculate the date we want. Each example will get the date you want to calculate by calculating the previous time interval and then adding and reducing it.
Th
Common date functions
SQL Server time and date function detailed, SQL Server, time, date,
1. Current system date, time
Select GETDATE ()
2. DateAdd returns a new datetime value on t
()
Returns the number of days between two dates
Date_format ()
Display Date/time in a different format
SQL Server Date functionThe following table lists the most important built-in date functions in S
other examples, only the datediff and dateadd functions are used to calculate the desired date. In each example, the date to be calculated is obtained through calculation but the previous time interval, and then addition or subtraction is performed.This is the SQL script used to calculate the first day of a month:Sele
will only use the datediff and dateadd functions to calculate the date we want. In each example, the date to be calculated is obtained through calculation but the previous time interval, and then addition or subtraction is performed.This is the SQL script used to calculate the first day of a month:Select dateadd (mm,
database table, performing operations on partial cursors not on the function, sending an email, and attempting to modify the directory, and generate the result set returned to the user. Stored procedures do not have this restriction5. The function can return only one variable. The stored procedure can return multiple
Development History
User-defined functions are supported after SqlServer 2000
Composition
In SQL
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.