Source post address click open link ACCESS statement: select * from data table where (DateDiff (d, Date Field, Date () 0) syntax DateDiff (interval, date1, date2 [, firstdayofweek] [, firstweekofyear]) the syntax of the DateDiff function contains
1. The first day of this monthSelect dateadd (mm, datediff (mm, 0, getdate (), 0)
2. Last day of the monthSelect dateadd (MS,-3, dateadd (mm, datediff (M, 0, getdate () + 1, 0 ))
3. The first day of last monthSelect dateadd (M,-1, dateadd (mm,
SQL Server date calculation
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 probably know how to divide a date (year, month,
The first day (DATEFIRST) determines the day your system uses as the first day of the week. All of the following examples are created on Sunday as the first day of the week, that is, the first day of the week is set to 7. If your first day settings
SQL Server Date Calculation
Usually, you need to get the current date and calculate some other date, for example, your program may need to judge the first or last day of one months. Most of you probably know how to split dates (year, month, day, etc.
Special instructions under: The following statistics this week data, Sunday is as the first day of next week, and not the last day of the week, so you put Sunday as the last day of the week, you need to getDate () on the basis of the reduction of
1. First day of the monthSELECT DATEADD (mm, DATEDIFF (Mm,0,getdate ()), 0)2. Last day of the monthSELECT DateAdd (Ms,-3,dateadd (mm, DATEDIFF (M,0,getdate ()) +1, 0))3. The first day of the monthSelect DATEADD (m,-1, DateAdd (mm, DATEDIFF
------------------date is converted into a month and a day and seconds---------------Select ' R ' +convert (varchar), GETDATE (), 112)+right (CAST (Power (10,2) as varchar) +datepart (hour, GETDATE ()), 2)+right (CAST (Power (10,2) as varchar)
Select GETDATE () as ' current date ',Datename (Year,getdate ()) as ' year ',Datename (Month,getdate ()) as ' month ',Datename (Day,getdate ()) as ' Day ',Datename (Dw,getdate ()) as ' Week ',Datename (Week,getdate ()) as ' Week number ',Datename
Refer to the following date Writing Method--- Calculate the number of days for differenceSelect datediff (day, '2017-01-01 ', getdate ())
-- 1. The first day of a monthSelect dateadd (mm, datediff (mm, 0, getdate (), 0)
-- 2. Monday of the
1. show the first day of this month SELECTDATEADD (mm, DATEDIFF (mm, 0, getdate (), 0) selectconvert (datetime, convert (varchar (8), getdate (), 120) + 01,120) 2. displays the last day of the month selectdateadd (day,-1, convert (datetime, convert (
The specific website is not saved, but I am used to saving the code remembered method. Now I am posting it. I hope the original author will be considerate.Copy codeThe Code is as follows:--- First day of last monthSelect CONVERT (varchar (12),
The specific website is not saved, but I am used to it.
Code Remember to save the method and paste it now. I hope the original author will be considerate.
Copy code The Code is as follows: --- the first day of the first month of last month
Select
Example: DateDiff (Dd,add_time,getdate ()) not between 0 and 7Select COUNT (*) fromtable where DATEDIFF ([second], ' 2004-09-18 00:00:18 ', ' 2004-09-18 00:00:19 ') > 0DescriptionSelect DATEDIFF (Day, time1, time2) corresponds to the following
Last day of last month This is an example that calculates the last day of the last month. It is obtained by subtracting 3 milliseconds from the example on the last day of one months. One thing to keep in mind is that the time in SQL Server is
The specific URL is not saved, but I this person is accustomed to good code to remember the way to save, now posted out, I hope the original author understanding.
Copy CodeThe code is as follows:
---The first day of the month
Select CONVERT
Usually, you need to get the current date and calculate some other date, for example, your program may need to judge the first or last day of one months. Most of you probably know how to split dates (year, month, day, etc.), and then just use the
One, SQL Server time Date function detailed1. 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 '
--- First day of last monthSelect convert (varchar (12), dateadd (mm, datediff (mm, 0, dateadd (mm,-1, getdate (), 0), 112)--- Last day of last monthSelect convert (varchar (12), dateadd (MS,-3, dateadd (mm, datediff (M, 0, getdate (), 0), 112)
1.
Now () gets the current system Date and Time. asp output can be written as follows:
Year (now () gets the year, ASP output:
Month (now () gets the current month, ASP output:
When day (now () is obtained, ASP outputs:
Minute (now () gets the
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.