Friday, November 13, 2009

SQL manipulating date time using CONVERT

SELECT status, event_id, title, CONVERT(VARCHAR(12),event_date,107) as edate, dbo.udf_DayOfWeek(event_date) AS DayOfWeek from tblEvent where Convert(datetime,Convert(varchar(12), event_date, 103),103) >= Convert(datetime,Convert(varchar(12), GETDATE(),103),103) order by event_date

SELECT status, event_id, title, CONVERT(VARCHAR(12),event_date,107) as edate, dbo.udf_DayOfWeek(event_date) AS DayOfWeek from tblEvent where Convert(datetime,Convert(VARCHAR(12), event_date, 103),103) < Convert(datetime,Convert(VARCHAR(12), GETDATE(),103),103) AND Convert(datetime,Convert(VARCHAR(12), event_date, 103),103) > Convert(datetime,datediff(day, 30, GETDATE()),103) order by event_date DESC

No comments: