DateTime 数字型 ......
1、DateTime 数字型
System.DateTime currentTime=new System.DateTime();
1.1 取当前年月日时分秒
currentTime=System.DateTime.Now;
1.2 取当前年
int 年=currentTime.Year;
1.3 取当前月
int 月=currentTime.Month;
1.4 取当前日
int 日=currentTime.Day;
1.5 取当前时
int 时=currentTime.Hour;
1.6 取当前分
int 分=currentTime.Minute;
1.7 取当前秒
int 秒=currentTime.Second;
1.8 取当前毫秒
int 毫秒=currentTime.Millisecond;
(变量可用中文) chinaitpower.comNJMNpKx60pHmoHa
1.9 取中文日期显示——年月日时分
string strY=currentTime.ToString("f"); //不显示秒 chinaitpower.comNJMNpKx60pHmoHa
1.10 取中文日期显示_年月
string strYM=currentTime.ToString("y"); chinaitpower.comNJMNpKx60pHmoHa
1.11 取中文日期显示_月日
string strMD=currentTime.ToString("m"); chinaitpower.comNJMNpKx60pHmoHa
1.12 取当前年月日,格式为:2003-9-23
string strYMD=currentTime.ToString("d"); chinaitpower.comNJMNpKx60pHmoHa
1.13 取当前时分,格式为:14:24
string strT=currentTime.ToString("t"); chinaitpower.comNJMNpKx60pHmoHa
2、Int32.Parse(变量) Int32.Parse("常量")
字符型转换 转为32位数字型 chinaitpower.comNJMNpKx60pHmoHa
从smalldatetime类型中怎么查找到是某一年的记录出来
我的数据表是如下的:
attdate name
------------------------------
2001-4-2 12:00:00 cheng
2002-12-2 12:00:00 zhang
2003-12-2 12:00:00 huang
2002-12-2 12:00:00 zhang
……
------------------------------
attdate是smalldatetime型的.怎么从数据库中取出2002年的所有记录出来呢?
select * from 表 where year(attdate) = 2002
select * from 表 where convert(char(4),attdate,120) = '2002'
select * from 表 where datepard(year,attdate) = 2002
select * from 表 where datediff(year,'2002-01-01',attdate) = 0
如果要查哪一年哪一月的呢?
----------------------------------------------------------------
比如查询2002年6月
select * from 表 where year(attdate) = 2002 and month(attdate) = 6
select * from 表 where convert(char(7),attdate,120) = '2002-06'
select * from 表 where datepard(year,attdate) = 2002 and datepard(month,attdate) = 6
select * from 表 where datediff(month,'2002-06-01',attdate) = 0
取出来时间格式
select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
select convert(char(8),getdate(),112) ----20020101
select convert(char(8),getdate(),108) ---06:05:05
101 美国 mm/dd/yyyy
2 102 ANSI yy.mm.dd
3 103 英国/法国 dd/mm/yy
4 104 德国 dd.mm.yy
5 105 意大利 dd-mm-yy
6 106 - dd mon yy
7 107 - mon dd, yy
8 108 - hh:mm:ss
- 9 或 109 (*) 默认值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM)
10 110 美国 mm-dd-yy
11 111 日本 yy/mm/dd
12 112 ISO yymmdd
- 13 或 113 (*) 欧洲默认值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm(24h)
- 20 或 120 (*) ODBC 规范 yyyy-mm-dd hh:mm:ss[.fff]
- 21 或 121 (*) ODBC 规范(带毫秒) yyyy-mm-dd hh:mm:ss[.fff]
- 126(***) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(不含空格)
- 130* 科威特 dd mon yyyy hh:mi:ss:mmmAM
- 131* 科威特 dd/mm/yy hh:mi:ss:mmmAM