Table of Contents

Class DateTimeExtensions

Namespace
MongoDB.Driver.Linq
Assembly
MongoDB.Driver.dll

This static class holds methods that can be used to express MongoDB specific operations in LINQ queries.

public static class DateTimeExtensions
Inheritance
DateTimeExtensions
Inherited Members

Methods

Add(DateTime, long, DateTimeUnit)

Adds a value of the specified unit to a DateTime.

public static DateTime Add(this DateTime @this, long value, DateTimeUnit unit)

Parameters

this DateTime

The original DateTime.

value long

The value to be added.

unit DateTimeUnit

The unit.

Returns

DateTime

The resulting DateTime.

Add(DateTime, long, DateTimeUnit, string)

Adds a value of the specified unit to a DateTime taking a timezone into consideration.

public static DateTime Add(this DateTime @this, long value, DateTimeUnit unit, string timezone)

Parameters

this DateTime

The original DateTime.

value long

The value to be added.

unit DateTimeUnit

The unit.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

Add(DateTime, TimeSpan, string)

Adds a TimeSpan value to a DateTime taking a timezone into consideration.

public static DateTime Add(this DateTime @this, TimeSpan value, string timezone)

Parameters

this DateTime

The original DateTime.

value TimeSpan

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddDays(DateTime, double, string)

Adds a value in days to a DateTime taking a timezone into consideration.

public static DateTime AddDays(this DateTime @this, double value, string timezone)

Parameters

this DateTime

The original DateTime.

value double

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddHours(DateTime, double, string)

Adds a value in hours to a DateTime taking a timezone into consideration.

public static DateTime AddHours(this DateTime @this, double value, string timezone)

Parameters

this DateTime

The original DateTime.

value double

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddMilliseconds(DateTime, double, string)

Adds a value in milliseconds to a DateTime taking a timezone into consideration.

public static DateTime AddMilliseconds(this DateTime @this, double value, string timezone)

Parameters

this DateTime

The original DateTime.

value double

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddMinutes(DateTime, double, string)

Adds a value in minutes to a DateTime taking a timezone into consideration.

public static DateTime AddMinutes(this DateTime @this, double value, string timezone)

Parameters

this DateTime

The original DateTime.

value double

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddMonths(DateTime, int, string)

Adds a value in months to a DateTime taking a timezone into consideration.

public static DateTime AddMonths(this DateTime @this, int value, string timezone)

Parameters

this DateTime

The original DateTime.

value int

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddQuarters(DateTime, int)

Adds a value in quarters to a DateTime.

public static DateTime AddQuarters(this DateTime @this, int value)

Parameters

this DateTime

The original DateTime.

value int

The value to be added.

Returns

DateTime

The resulting DateTime.

AddQuarters(DateTime, int, string)

Adds a value in quarters to a DateTime taking a timezone into consideration.

public static DateTime AddQuarters(this DateTime @this, int value, string timezone)

Parameters

this DateTime

The original DateTime.

value int

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddSeconds(DateTime, double, string)

Adds a value in seconds to a DateTime taking a timezone into consideration.

public static DateTime AddSeconds(this DateTime @this, double value, string timezone)

Parameters

this DateTime

The original DateTime.

value double

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddWeeks(DateTime, int)

Adds a value in weeks to a DateTime taking.

public static DateTime AddWeeks(this DateTime @this, int value)

Parameters

this DateTime

The original DateTime.

value int

The value to be added.

Returns

DateTime

The resulting DateTime.

AddWeeks(DateTime, int, string)

Adds a value in weeks to a DateTime taking a timezone into consideration.

public static DateTime AddWeeks(this DateTime @this, int value, string timezone)

Parameters

this DateTime

The original DateTime.

value int

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

AddYears(DateTime, int, string)

Adds a value in years to a DateTime taking a timezone into consideration.

public static DateTime AddYears(this DateTime @this, int value, string timezone)

Parameters

this DateTime

The original DateTime.

value int

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateAdd for information on timezones in MongoDB.

Subtract(DateTime, DateTime, DateTimeUnit)

Subtracts the start date from the end date returning the result in the specified unit.

public static long Subtract(this DateTime @this, DateTime startDate, DateTimeUnit unit)

Parameters

this DateTime

The original DateTime.

startDate DateTime

The start date.

unit DateTimeUnit

The unit.

Returns

long

The result.

Subtract(DateTime, DateTime, DateTimeUnit, string)

Subtracts the start date from the end date returning the result in the specified unit taking a timezone into consideration.

public static long Subtract(this DateTime @this, DateTime startDate, DateTimeUnit unit, string timezone)

Parameters

this DateTime

The original DateTime.

startDate DateTime

The start date.

unit DateTimeUnit

The unit.

timezone string

The timezone.

Returns

long

The result.

Remarks

See the server documentation for $dateDiff for information on timezones in MongoDB.

Subtract(DateTime, DateTime, string)

Subtracts the start date from the end date returning a TimeSpan taking a timezone into consideration.

public static TimeSpan Subtract(this DateTime @this, DateTime value, string timezone)

Parameters

this DateTime

The original DateTime.

value DateTime

The value to be added.

timezone string

The timezone.

Returns

TimeSpan

The resulting DateTime.

Remarks

See the server documentation for $dateDiff for information on timezones in MongoDB.

Subtract(DateTime, long, DateTimeUnit)

Subtracts a value of the specified unit from a DateTime.

public static DateTime Subtract(this DateTime @this, long value, DateTimeUnit unit)

Parameters

this DateTime

The original DateTime.

value long

The value to be added.

unit DateTimeUnit

The unit.

Returns

DateTime

The resulting DateTime.

Subtract(DateTime, long, DateTimeUnit, string)

Subtracts a value of the specified unit from a DateTime taking a timezone into consideration.

public static DateTime Subtract(this DateTime @this, long value, DateTimeUnit unit, string timezone)

Parameters

this DateTime

The original DateTime.

value long

The value to be added.

unit DateTimeUnit

The unit.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateSubtract for information on timezones in MongoDB.

Subtract(DateTime, TimeSpan, string)

Subtracts a TimeSpan from a date taking a timezone into consideration.

public static DateTime Subtract(this DateTime @this, TimeSpan value, string timezone)

Parameters

this DateTime

The original DateTime.

value TimeSpan

The value to be added.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateSubtract for information on timezones in MongoDB.

ToString(DateTime, string, string)

Converts a DateTime value to a string.

public static string ToString(this DateTime @this, string format, string timezone)

Parameters

this DateTime

The DateTime value.

format string

The format string (optional, can be null).

timezone string

The timezone to use in the returned string (optional, can be null).

Returns

string

The DateTime value converted to a string.

Truncate(DateTime, DateTimeUnit)

Truncates a DateTime value to the specified unit.

public static DateTime Truncate(this DateTime @this, DateTimeUnit unit)

Parameters

this DateTime

The original DateTime.

unit DateTimeUnit

The unit.

Returns

DateTime

The resulting DateTime.

Truncate(DateTime, DateTimeUnit, long)

Truncates a DateTime value to the specified unit and bin size.

public static DateTime Truncate(this DateTime @this, DateTimeUnit unit, long binSize)

Parameters

this DateTime

The original DateTime.

unit DateTimeUnit

The unit.

binSize long

The bin size.

Returns

DateTime

The resulting DateTime.

Truncate(DateTime, DateTimeUnit, long, string)

Truncates a DateTime value to the specified unit and bin size taking a timezone into consideration.

public static DateTime Truncate(this DateTime @this, DateTimeUnit unit, long binSize, string timezone)

Parameters

this DateTime

The original DateTime.

unit DateTimeUnit

The unit.

binSize long

The bin size.

timezone string

The timezone.

Returns

DateTime

The resulting DateTime.

Remarks

See the server documentation for $dateTrunc for information on timezones in MongoDB.

Week(DateTime)

Returns the week number of a specified DateTime value.

public static int Week(this DateTime @this)

Parameters

this DateTime

The DateTime value.

Returns

int

The week number of a specified DateTime value.

Week(DateTime, string)

Returns the week number of a specified DateTime value.

public static int Week(this DateTime @this, string timezone)

Parameters

this DateTime

The DateTime value.

timezone string

The timezone to use (optional, can be null).

Returns

int

The week number of a specified DateTime value.