日期与字符串之间的转换
1、使用函数CONVERT
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
2、常用案例
2.1 日期转字符串
Select CONVERT(varchar(100), GETDATE(), 20);
Select CONVERT(varchar(100), GETDATE(), 25);
Select CONVERT(varchar(10), GETDATE(), 20);
Select CONVERT(varchar(100), GETDATE(), 111);
Select CONVERT(varchar(100), GETDATE(), 112);
2.2 日期与时间函数运用
select dateadd(day,2,'2023-08-02 20:40:00');
SELECT DATEPART(year, '2023-08-02');
SELECT DATEPART(month, '2023-08-02');
SELECT DATEPART(day, '2023-08-02');
SELECT * FROM [tableName] WHERE datediff(day, [字段名] ,getdate())=0
SELECT * FROM [tableName] WHERE datediff(week, [字段名] ,getdate())=0
SELECT * FROM [tableName] WHERE datediff(month, [字段名] ,getdate())=0
SELECT * FROM [tableName] WHERE datediff(quarter, [字段名] ,getdate())=0
SELECT * FROM [tableName] WHERE datediff(year, [字段名] ,getdate())=0