数据库中直接取得上面说了我就不说了,如果要在程序中处理,可以这样:dim strDate as Date = "2005-01-01"dim strYeat as String = Format(strDate,"yyyy") dim strMon as String = Format(strDate,"MM") dim strDay as String = Format(strDate,"dd")
最好是在程序里取 上面说的很详细了转换成datetime类型的数据后,用日期提供的方法DateTime MyDT = Convert.ToDateTime(字段) int iYear = MtDT.Year; 月日都是一样的
从数据库中取出数据后转换成DateTime型,然后就可以取年,月,日了.
DateTime dt = (DateTime)字段值
int yearValue = dt.Year;
int monthValue = dt.Month;
int dayValue = dt.Day;
FROM 表名
DATEPART( )
返回日期或日期时间列的指定部分,包括日、月或年。
Rright(DatePart("yyyy",datetime),1)返回年份的最后一位数字
dim strMon as String = Format(strDate,"MM")
dim strDay as String = Format(strDate,"dd")
上面说的很详细了转换成datetime类型的数据后,用日期提供的方法DateTime MyDT = Convert.ToDateTime(字段)
int iYear = MtDT.Year;
月日都是一样的