本文整理汇总了C#中Field.AsDate方法的典型用法代码示例。如果您正苦于以下问题:C# Field.AsDate方法的具体用法?C# Field.AsDate怎么用?C# Field.AsDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Field
的用法示例。
在下文中一共展示了Field.AsDate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDate
public static Field AddDate(Field dateField, Field datePart, Field value)
{
if (dateField.IsNull)
return Field.Date(SqlDateTime.Null);
var date = (SqlDateTime) dateField.AsDate().Value;
var partString = datePart.AsVarChar().Value.ToString();
var iValue = ((SqlNumber) value.AsInteger().Value).ToInt32();
SqlDateTime result;
switch (partString.ToUpperInvariant()) {
case "YEAR":
result = date.Add(new SqlYearToMonth(iValue, 0));
break;
case "MONTH":
result = date.Add(new SqlYearToMonth(iValue));
break;
case "DAY":
result = date.Add(new SqlDayToSecond(iValue, 0, 0, 0, 0));
break;
case "HOUR":
result = date.Add(new SqlDayToSecond(0, iValue, 0, 0));
break;
case "MINUTE":
result = date.Add(new SqlDayToSecond(0, 0, iValue, 0));
break;
case "SECOND":
result = date.Add(new SqlDayToSecond(0, 0, 0, iValue, 0));
break;
case "MILLIS":
case "MILLISECOND":
result = date.Add(new SqlDayToSecond(0, 0, 0, 0, iValue));
break;
default:
throw new ArgumentException(String.Format("The date part '{0}' is invalid", partString));
}
return Field.Date(result);
}
示例2: Extract
public static Field Extract(Field dateField, Field datePart)
{
if (dateField.IsNull)
return Field.Number(SqlNumber.Null);
var date = (SqlDateTime)dateField.AsDate().Value;
var partString = datePart.AsVarChar().Value.ToString();
int result;
switch (partString.ToUpperInvariant()) {
case "YEAR":
result = date.Year;
break;
case "MONTH":
result = date.Month;
break;
case "DAY":
result = date.Day;
break;
case "HOUR":
result = date.Hour;
break;
case "MINUTE":
result = date.Minute;
break;
case "SECOND":
result = date.Second;
break;
case "MILLIS":
case "MILLISECOND":
result = date.Millisecond;
break;
default:
throw new ArgumentException(String.Format("The date part '{0}' is invalid", partString));
}
return Field.Integer(result);
}