SqlFunctions.DateDiff Method

Definition

Returns the number of date and time boundaries crossed between two specified dates.

Overloads

DateDiff(String, String, String)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, String, Nullable<TimeSpan>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, String, Nullable<DateTimeOffset>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, String, Nullable<DateTime>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<TimeSpan>, String)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<TimeSpan>, Nullable<TimeSpan>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<TimeSpan>, Nullable<DateTimeOffset>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<TimeSpan>, Nullable<DateTime>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<DateTimeOffset>, Nullable<DateTimeOffset>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<DateTimeOffset>, Nullable<TimeSpan>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<DateTimeOffset>, String)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<DateTimeOffset>, Nullable<DateTime>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<DateTime>, String)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<DateTime>, Nullable<TimeSpan>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<DateTime>, Nullable<DateTimeOffset>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

DateDiff(String, Nullable<DateTime>, Nullable<DateTime>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

DateDiff(String, String, String)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, string startDate, string endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
String

The first date.

endDate
String

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, String, Nullable<TimeSpan>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, string startDate, TimeSpan? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
String

The first date.

endDate
Nullable<TimeSpan>

The second date.

Returns

The value specifying the number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, String, Nullable<DateTimeOffset>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, string startDate, DateTimeOffset? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
String

The first date.

endDate
Nullable<DateTimeOffset>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, String, Nullable<DateTime>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, string startDate, DateTime? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
String

The first date.

endDate
Nullable<DateTime>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<TimeSpan>, String)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, TimeSpan? startDate, string endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<TimeSpan>

The first date.

endDate
String

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<TimeSpan>, Nullable<TimeSpan>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, TimeSpan? startDate, TimeSpan? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<TimeSpan>

The first date.

endDate
Nullable<TimeSpan>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<TimeSpan>, Nullable<DateTimeOffset>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, TimeSpan? startDate, DateTimeOffset? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<TimeSpan>

The first date.

endDate
Nullable<DateTimeOffset>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<TimeSpan>, Nullable<DateTime>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, TimeSpan? startDate, DateTime? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<TimeSpan>

The first date.

endDate
Nullable<DateTime>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<DateTimeOffset>, Nullable<DateTimeOffset>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, DateTimeOffset? startDate, DateTimeOffset? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<DateTimeOffset>

The first date.

endDate
Nullable<DateTimeOffset>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<DateTimeOffset>, Nullable<TimeSpan>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, DateTimeOffset? startDate, TimeSpan? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<DateTimeOffset>

The first date.

endDate
Nullable<TimeSpan>

The second date.

Returns

The number of time intervals between the two Dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<DateTimeOffset>, String)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, DateTimeOffset? startDate, string endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<DateTimeOffset>

The first date.

endDate
String

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<DateTimeOffset>, Nullable<DateTime>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, DateTimeOffset? startDate, DateTime? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<DateTimeOffset>

The first date.

endDate
Nullable<DateTime>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<DateTime>, String)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, DateTime? startDate, string endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<DateTime>

The first date.

endDate
String

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<DateTime>, Nullable<TimeSpan>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, DateTime? startDate, TimeSpan? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<DateTime>

The first date.

endDate
Nullable<TimeSpan>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<DateTime>, Nullable<DateTimeOffset>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, DateTime? startDate, DateTimeOffset? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<DateTime>

The first date.

endDate
Nullable<DateTimeOffset>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

DateDiff(String, Nullable<DateTime>, Nullable<DateTime>)

Returns the count of the specified datepart boundaries crossed between the specified start date and end date.

C#
[System.Data.Objects.DataClasses.EdmFunction("SqlServer", "DATEDIFF")]
public static int? DateDiff(string datePartArg, DateTime? startDate, DateTime? endDate);

Parameters

datePartArg
String

The part of the date to calculate the differing number of time intervals.

startDate
Nullable<DateTime>

The first date.

endDate
Nullable<DateTime>

The second date.

Returns

The number of time intervals between the two dates.

Attributes

Remarks

You cannot call this function directly. This function can only appear within a LINQ to Entities query.

This function is translated to a corresponding function in the database. For information about the corresponding SQL Server function, see DATEDIFF (Transact-SQL).

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1