I encountered a problem today. I want to query the data added to a table today and solve it later. Well, record it:
Select * from table 1 where convert (varchar (10), table 1. Creation Time, 120) = convert (varchar (10), getdate (), 120)
For this month:
Select * from table 1 where convert (varchar (7), table 1. Creation Time, 120) = convert (varchar (7), getdate (), 120)
For this purpose, I checked the date function and recorded it:
1. dateadd adds a period of time to the specified date and returns a new datetime value, for example, dateadd (day, 2, '2017-09-22 ')
2. datediff returns the time difference between two dates, for example, datediff (day, '2017-09-22 ', '2017-09-18 '): returns the number of days between two dates (the last minus the previous one)
3. datepart returns the integer of the specified date part of the specified date, for example, datepart (month, '2017-10-15 ')
4. datename returns the string of the specified date part of the specified date, for example, select datename (weekday, '2017-10-15 ') -- Return: Friday
Finally, remember that getdate () is used to obtain the current time.
Processing of some date Conditions