Search This Blog

Saturday, June 9, 2012

Date Functions C#

C# > System Namespace > DateTime > Add Methods

Returns a new DateTime that adds the specified number of  years, days, minutes, months, seconds to the value of this instance.

Example:

DateTime AgendaValidTill = DateTime.Now.AddYears(10);
// add days
AgendaValidTill = DateTime.Now.AddDays(10);
AgendaValidTill = DateTime.Now.AddMinutes(10);
AgendaValidTill = DateTime.Now.AddMonths(10);
AgendaValidTill = DateTime.Now.AddSeconds(10);








Wednesday, June 6, 2012

Date functions SQL Server

SQL Server > Date&Time > Date Functions



-- Selecting the Current Year/Get Current Year/Separate Year Part from Date
Select DatePart(YY, GetDate()) as Current_Year
-- Selecting the Current Quarter/Get Current Quarter/Separate Quarter Part from Date
Select DatePart(QQ, GetDate()) as Current_Quarter
-- Selecting the Current Month/Get Current Month/Separate Month Part from Date
Select DatePart(MM, GetDate()) as Current_Month
-- Selecting the Current Hour/Get Current Hour/Separate Hour Part from Date
Select DatePart(HH, GetDate()) as Current_Hour
-- Selecting the Current Minute/Get Current Minute/Separate Minute Part from Date
Select DatePart(minute, GetDate()) as Current_Minute

-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(month, GetDate()) as Current_Month_Name
-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(day, GetDate()) as Current_Day
-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(wk, GetDate()) as Current_Week