Date/time functions in SQL Server 2005
-
Hi All, I am looking for the functions in SQL server which would return me the mid day, last day of the month given the current date and the param. I would appreciate if you could point me to some related links. I have written some SQLs to do this but looks very ugly with lots of code. Input will be some date and period. Output will be the Till ending date interval1 and Till ending date interval2 If period(1) = weekly then the Till ending date = end of the current week (Sun) - I assume a week begins on Monday. If period(2) = bi-weekly then the Till ending date = end of the following week (Sun) If period(3) = semi-monthly & today <= 15th of the month then the Till ending date = 15th of the current month, otherwise Till ending date = end of month. If period(4) = monthly then the Till ending date = end of month For example: Input Some_date : 1-Jan-2006 Period Output Period Out1 Out2 1 8-Jan 15-Jan 2 15-Jan 29-Jan 3 15-Jan 31-Jan 4 31-Jan 28-Feb Thanks for the help.
-
Hi All, I am looking for the functions in SQL server which would return me the mid day, last day of the month given the current date and the param. I would appreciate if you could point me to some related links. I have written some SQLs to do this but looks very ugly with lots of code. Input will be some date and period. Output will be the Till ending date interval1 and Till ending date interval2 If period(1) = weekly then the Till ending date = end of the current week (Sun) - I assume a week begins on Monday. If period(2) = bi-weekly then the Till ending date = end of the following week (Sun) If period(3) = semi-monthly & today <= 15th of the month then the Till ending date = 15th of the current month, otherwise Till ending date = end of month. If period(4) = monthly then the Till ending date = end of month For example: Input Some_date : 1-Jan-2006 Period Output Period Out1 Out2 1 8-Jan 15-Jan 2 15-Jan 29-Jan 3 15-Jan 31-Jan 4 31-Jan 28-Feb Thanks for the help.
Do you have SQL Server Help? Start by looking at the help for functions GETDATE() and DATEPART(). Then follow other related links from there. Scott