This project has moved. For the latest updates, please go here.

System.DateTime Extension Methods

DateTime.EndOfDay Method

A DateTime extension method that return a DateTime with the time set to "23:59:59:999". The last moment of the
day.

Syntax

DateTime EndOfDay(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_EndOfDay
     {
         [TestMethod]
         public void EndOfDay()
         {
             // Type
             DateTime @this = DateTime.Now;
 
             // Examples
             DateTime value = @this.EndOfDay(); // value = "yyyy/MM/dd 23:59:59:999";
 
             // Unit Test
             Assert.AreEqual(new DateTime(value.Year, value.Month, value.Day, 23, 59, 59, 999), value);
         }
     }
 }
                

DateTime.EndOfMonth Method

A DateTime extension method that return a DateTime of the last day of the month with the time set to
"23:59:59". The last moment of the day.

Syntax

DateTime EndOfMonth(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_EndOfMonth
     {
         [TestMethod]
         public void EndOfMonth()
         {
             // Type
             var @this = new DateTime(2013, 12, 22);
 
             // Examples
             DateTime value = @this.EndOfMonth(); // value = "2013/12/31 23:59:59:999";
 
             // Unit Test
             Assert.AreEqual(new DateTime(2013, 12, 31, 23, 59, 59, 999), value);
         }
     }
 }
                

DateTime.EndOfYear Method

A DateTime extension method that return a DateTime of the last day of the year with the time set to
"23:59:59". The last moment of the day.

Syntax

DateTime EndOfYear(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_EndOfYear
     {
         [TestMethod]
         public void EndOfYear()
         {
             // Type
             var @this = new DateTime(2013, 04, 13);
 
             // Examples
             DateTime value = @this.EndOfYear(); // value = "2013/12/31 23:59:59:999";
 
             // Unit Test
             Assert.AreEqual(new DateTime(2013, 12, 31, 23, 59, 59, 999), value);
         }
     }
 }
                

DateTime.IsFuture Method

A DateTime extension method that query if '@this' is in the future.

Syntax

bool IsFuture(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_IsFuture
     {
         [TestMethod]
         public void IsFuture()
         {
             // Type
             DateTime @this = DateTime.Now.AddDays(1);
 
             // Examples
             bool value1 = @this.IsFuture(); // return true;
             bool value2 = @this.AddYears(-1).IsFuture(); // return false;
 
             // Unit Test
             Assert.IsTrue(value1);
             Assert.IsFalse(value2);
         }
     }
 }
                

DateTime.IsPast Method

A DateTime extension method that query if '@this' is in the past.

Syntax

bool IsPast(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_IsPast
     {
         [TestMethod]
         public void IsPast()
         {
             // Type
             DateTime @this = DateTime.Now.AddDays(1);
 
             // Examples
             bool value1 = @this.IsPast(); // return false;
             bool value2 = @this.AddYears(-1).IsPast(); // return true;
 
             // Unit Test
             Assert.IsFalse(value1);
             Assert.IsTrue(value2);
         }
     }
 }
                

DateTime.IsWeekDay Method

A DateTime extension method that query if '@this' is a week day.

Syntax

bool IsWeekDay(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_IsWeekDay
     {
         [TestMethod]
         public void IsWeekDay()
         {
             // Type
             var @thisFriday = new DateTime(2013, 11, 22); // Friday
             var @thisSaturday = new DateTime(2013, 11, 23); // Saturday
 
             // Examples
             bool value1 = @thisFriday.IsWeekDay(); // return true;
             bool value2 = @thisSaturday.IsWeekDay(); // return false;
 
             // Unit Test
             Assert.IsTrue(value1);
             Assert.IsFalse(value2);
         }
     }
 }
                

DateTime.IsWeekendDay Method

A DateTime extension method that query if '@this' is a weekend day.

Syntax

bool IsWeekendDay(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_IsWeekendDay
     {
         [TestMethod]
         public void IsWeekendDay()
         {
             // Type
             var @thisFriday = new DateTime(2013, 11, 22); // Friday
             var @thisSaturday = new DateTime(2013, 11, 23); // Saturday
 
             // Examples
             bool value1 = @thisFriday.IsWeekendDay(); // return false;
             bool value2 = @thisSaturday.IsWeekendDay(); // return true;
 
             // Unit Test
             Assert.IsFalse(value1);
             Assert.IsTrue(value2);
         }
     }
 }
                

DateTime.StartOfDay Method

A DateTime extension method that return a DateTime with the time set to "00:00:0". The first moment of the
day.

Syntax

DateTime StartOfDay(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_StartOfDay
     {
         [TestMethod]
         public void StartOfDay()
         {
             // Type
             DateTime @this = DateTime.Now;
 
             // Examples
             DateTime value = @this.StartOfDay(); // value = "yyyy/MM/dd 00:00:00:000";
 
             // Unit Test
             Assert.AreEqual(new DateTime(value.Year, value.Month, value.Day), value);
         }
     }
 }
                

DateTime.StartOfMonth Method

A DateTime extension method that return a DateTime of the first day of the month with the time set to
"00:00:00". The first moment of the day.

Syntax

DateTime StartOfMonth(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_StartOfMonth
     {
         [TestMethod]
         public void StartOfMonth()
         {
             // Type
             DateTime @this = DateTime.Now;
 
             // Examples
             DateTime value = @this.StartOfMonth(); // value = "yyyy/MM/01 00:00:00:000";
 
             // Unit Test
             Assert.AreEqual(new DateTime(value.Year, value.Month, 1), value);
         }
     }
 }
                

DateTime.StartOfYear Method

A DateTime extension method that return a DateTime of the first day of the year with the time set to
"00:00:00". The first moment of the day.

Syntax

DateTime StartOfYear(DateTime @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_DateTime_StartOfYear
     {
         [TestMethod]
         public void StartOfYear()
         {
             // Type
             DateTime @this = DateTime.Now;
 
             // Examples
             DateTime value = @this.StartOfYear(); // value = "yyyy/01/01 00:00:00:000";
 
             // Unit Test
             Assert.AreEqual(new DateTime(value.Year, 1, 1), value);
         }
     }
 }
                

Last edited Nov 23, 2013 at 6:53 PM by Jonathan_Magnan, version 1