Access日期和时间函数[1].doc_第1页
Access日期和时间函数[1].doc_第2页
Access日期和时间函数[1].doc_第3页
Access日期和时间函数[1].doc_第4页
Access日期和时间函数[1].doc_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1.Cdate(日期表达式)将日期表达式转换成日期类型的数据。日期表达式是任何可以解释成日期的表达式,包含日期文字,可以看作日期的字符串以及从函数返回的日期。比如:myDate = CDate(99-5-20) ,这样的日期表达式必须加双引号,否则结果不可预料。CDate 依据系统上的区域设置来决定日期的格式。如果提供的格式为不可识别的日期设置,则不能正确判断年、月、日的顺序。2.Now()返回当前计算机系统设置的日期和时间。3.Year(日期表达式)返回表示年份的整数。比如:Year(00-6-15) = 20004.Month(日期表达式)返回 1 到 12 之间的整数,表示一年中的某月。比如:Month(00-6-15) = 65.DateAdd(interval, number, date)DateAdd 函数语法中有下列命名参数:部分 描述interval 必要。字符串表达式,是所要加上去的时间间隔。number 必要。数值表达式,是要加上的时间间隔的数目。其数值可以为正数(得到未来的日期),也可以为负数(得到过去的日期)。date 必要。Variant (Date) 或表示日期的文字,这一日期还加上了时间间隔。设置 interval 参数具有以下设定值:设置 描述yyyy 年q 季m 月y 一年的日数d 日w 一周的日数ww 周h 时n 分钟s 秒说明可以使用 DateAdd 函数对日期加上或减去指定的时间间隔。例如,可以用 DateAdd 来计算距今天为三十天的日期;或者计算距现在为 45 分钟的时间。为了对 date 加上“日”,可以使用“一年的日数” (“y”),“日” (”d”) 或“一周的日数” (”w”)。DateAdd 函数将不返回有效日期。在以下实例中将 1 月31 日加上一个月:DateAdd(m, 1, 31-Jan-95)上例中,DateAdd 返回 1995 年 2 月 28 日,而不是 1995 年 2 月 31 日。如果 date 是 1996 年 1 月 31 日,则由于 1996 年是闰年,返回值是 1996 年 2 月 29 日。如果计算的日期超前 100 年(减去的年度超过 date 中的年份),就会导致错误发生。如果 number 不是一个 Long 值,则在计算时取最接近的整数值来计算。注意 DateAdd 返回值的格式由 Control Panel设置决定,而不是由传递到date 参数的格式决定。事例:DateAdd(d,10,2000-6-18)结果是: 2000-06-28DateAdd(m,-1,2000-6-18)结果是: 2000-05-186、DateDiff 函数返回 Variant (Long) 的值,表示两个指定日期间的时间间隔数目。语法 DateDiff(interval, date1, date2, firstdayofweek, firstweekofyear)DateDiff 函数语法中有下列命名参数:部分 描述interval 必要。字符串表达式,表示用来计算date1 和 date2 的时间差的时间间隔Date1date2 必要;Variant (Date)。计算中要用到的两个日期。Firstdayofweek 可选。指定一个星期的第一天的常数。如果未予指定,则以星期日为第一天。firstweekofyear 可选。指定一年的第一周的常数。如果未予指定,则以包含 1 月 1 日的星期为第一周。interval 参数的设定值同DateAdd函数,请参考上面的例子。例:DateDiff(d,#2004-01-06#,#2004-01-07#) 17、DatePart 函数返回一个包含已知日期的指定时间部分的 Variant (Integer)。语法 DatePart(interval, date,firstdayofweek, firstweekofyear)DatePart 函数语法中有下列命名参数:部分 描述interval 必要。字符串表达式,是要返回的时间间隔。date 必要。要计算的 Variant (Date) 值。Firstdayofweek 可选。指定一个星期的第一天的常数。如果未予指定,则以星期日为第一天。firstweekofyear 可选。指定一年第一周的常数。如果未予指定,则以包含 1 月 1 日的星期为第一周。设置interval 参数的设定值同DateAdd()DatePart 函数示例本示例先取得一个日期,然后使用 DatePart 函数显示该日期是发生在该年的哪一季。Dim TheDate As Date 声明变量。Dim MsgT12、Time 函数返回一个指明当前系统时间的 Variant (Date)。语法Time示例使用 Time 函数返回系统当前的时间。Dim MyTimeMyTime = Time 返回系统当前的时间说明为了设置系统时间,请使用 Time 语句。设置系统时间。语法Time = time必要的 time 参数,可以是任何能够表示时刻的数值表达式、字符串表达式或它们的组合。说明如果 time 是一字符串,则 Time 会试着根据系统指定的时间,利用时间分隔符将其转换成一个时间。如果无法转换成一个有效的时间,则会导致错误发生。13、FormatDateTime函数描述返回一个日期或时间格式的表达式。语法FormatDateTime(Date,NamedFormat)FormatDateTime函数语法有如下几部分:部分 描述Date 必需的。要被格式化的日期表达式NamedFormat可选的。数字值,表示日期/时间所使用的格式。如果忽略该值,则使用vbGeneralDate。设置值NamedFormat参数的设置值如下:常数 值 描述vbGeneralDate 0 显示日期和/或时间。如果有日期部分,则用短日期格式显示。如果有时间部分,则用长时间格式显示。如果都有,两部分都显示。VbLongDate 1 用计算机区域设置值中指定的长日期格式显示日期。VbShortDate 2 用计算机区域设置值中指定的短日期格式显示日期。18、用户自定义日期/时间格式 (Format 函数)下面标识一些可用来创建用户自定义日期/时间格式的字符:字符 说明(:) 时间分隔符。在一些区域,可能用其他符号来当时间分隔符。格式化时间值时,时间分隔符可以分隔时、分、秒。时间分隔符的真正字符在格式输出时取决于系统的设置。(/) 日期分隔符。在一些区域,可能用其他符号来当日期分隔符。格式化日期数值时,日期分隔符可以分隔年、月、日。日期分隔符的真正字符在格式输出时取决于系统设置。c 以 ddddd 来显示日期并且以 ttttt 来显示时间。如果想显示的数值无小数部分,则只显示日期部分,如果想显示的数值无整数部分,则只显示时间部分。d 以没有前导零的数字来显示日 (131)。dd 以有前导零的数字来显示日 (0131)。ddd 以简写来表示日 (SunSat)dddd 以全称来表示日 (SundaySaturday)ddddd 以完整日期表示法显示(包括年、月、日),日期的显示要依系统的短日期格式设置而定。dddddd 以完整日期表示法显示日期系列数(包括年、月、日),日期的显示要依系统识别的长日期格式而定。缺省的长日期格式为 mmmmdd, yyyy。aaaa 与dddd 一样,它只是该字符串的本地化版本。w 将一周中的日期以数值表示(1 表星期日 7表星期六)。ww 将一年中的星期以数值表示 (154)。m 以没有前导零的数字来显示月 (112)。如果 m 是直接跟在 h 或 hh 之后,那么显示的将是分而不是月。mm 以有前导零的数字来显示月 (01 12)。如果m是直接跟在h或hh之后,那么显示的将是分而不是月。mmm 以简写来表示月 (JanDec)。mmmm 以全称来表示月 (JanuaryDecember)。oooo 与mmmm一样,它只是该字符串的本地化版本。q 将一年如何将文本型:2003.08.04 转换为日期型:2003-08-04cdate(replace(2003.08.04,.,-)显示当前日期在该年中所处的星期号=Format(Now(), ww)ww 为 1 到 53。显示日期字段值的四位年份值。=DatePart(yyyy, 订购日期)显示日期字段值前 10 天的日期值。=DateAdd(y, -10, 应付日期)显示日期字段值前一个月的日期值。=DateAdd(m,-1,Date()显示日期1和日期2之间相差的天数。=DateDiff(d, 订购日期, 发货日期)从今天算起到三个月后的日期之间的记录。Betweeb date() and adddate(3,date()根据出生日期计算年龄(周岁)=IIf(Month(Date()-Month(出生年月日)-1,Year(Date()-Year(出生年月日),Year(Date()-Year(出生年月日)-1)日期函数示例当天日期:=Date()当日:=Day(date)当月:=Month(date()当年:=Year(date()当季:=DatePart(q,Date()算出每个月的天数一法:Dim a, b, ca = Year(Now()b = Month(Now()c = Format(a & / & b + 1 & /1), #) - Format(a & / & b & /1), #)二法:DateDiff(d, Format(Date, yyyy-mm-01), Format(DateAdd(m, -1, Date), yyyy-mm-01)DateDiff可以算出两个日期之间相差几天!三法:Day(DateAdd(d, -1, Format(Date, yyyy-mm-01)day函数可以知道某个日期是这个月的第几天,我们把这个月的最后一天拿出来DAY一下!应该还有更好的方法!比如说可以定义一个数组,把每个月的日子放进去,或者说写一个函数算每一个月的天数只要考虑一下闺年的问题就可以了!如何得到某年每个月的第一天是星期几Private Sub Command1_Click()Dim i As Integer, A As Integer, B As Integer, C As StringA = InputBox(请输入年份, 某年每个月的第一天是星期几)Form1.ClsFor i = 1 To 12C = A & - & i & -1B = Weekday(C)Select Case BCase vbSundayPrint A & 年 & i & 月1日是 星期日Case vbMondayPrint A & 年 & i & 月1日是 星期一Case vbTuesdayPrint A & 年 & i & 月1日是 星期二Case vbWednesdayPrint A &a-Sql Server中的日期与时间函数 ?蒰(寝 ?1. 当前系统日期、时间 F桗?赝Q?select getdate() 鈙H 倂建鶞Oh牧葵2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值r鯔俏? ?例如:向日期加上2天 ?5皴? 煃select dateadd(day,2,2004-10-15) -返回:2004-10-17 00:00:00.000Ew郬*矝?礛娞?3. datediff 返回跨两个指定日期的日期和时间边界数。jo u 秙 溽select datediff(day,2004-09-01,2004-09-18) -返回:17?鼄G驂W毰筒?4. datepart 返回代表指定日期的指定日期部分的整数。劸赔D/穙SELECT DATEPART(month, 2004-10-15) -返回 10Rk銍倝K$7$欤晛u!: ?5. datename 返回代表指定日期的指定日期部分的字符串堼梶 U咙SELECT datename(weekday, 2004-10-15) -返回:星期五S 吜瞎d湺 茜?鈠66. day(), month(),year() -可以与datepart对照一下V?u罞戀/m? HZ?Sselect 当前日期=convert(varchar(10),getdate(),120) s 喨?,当前时间=convert(varchar(8),getdate(),114) 即N 屾蛶4抗栳B銫K/select datename(dw,2004-10-15) ?3慯萳籋?b?|select 本年第多少周=datename(week,2004-10-15)宎梯d 短?,今天是周几=datename(weekday,2004-10-15)牶 ?1嶙挈鱒聈 W?n奄8姓婨?函数 参数/功能 y? 蓦?GetDate( ) 返回系统目前的日期与时间 瞫濾#縶?DateDiff (interval,date1,date2) 以interval 指定的方式,返回date2 与date1两个日期之间的差值 date2-date1 鸊脺 儔砍?DateAdd (interval,number,date) 以interval指定的方式,加上number之后的日期 鐺e蠅5流DatePart (interval,date) 返回日期date中,interval指定部分所对应的整数值 鑒/蟉错渥DateName (interval,date) 返回日期date中,interval指定部分所对应的字符串名称 杶逯 夤脅c呓h :l =?参数 interval的设定值如下:掅 YW 鲫=8?濠 ?值 缩 写(Sql Server) (Access 和 ASP) 说明 蔟 T)軤Year Yy yyyy 年 1753 9999 A玍癣0qgQuarter Qq q 季 1 4 駨#伥沠?F;Month Mm m 月1 12 O?c(a耀蒪Day of year Dy y 一年的日数,一年中的第几日 1-366 Y 觲挰 褽Day Dd d 日,1-31 粤茎綪嶴诳Weekday Dw w 一周的日数,一周中的第几日 1-7 襪齀 & ?Week Wk ww 周,一年中的第几周 0 51 ?X葤7 膧Hour Hh h 时0 23 F?F啇U暜?Minute Mi n 分钟0 59 貞r笍oSecond Ss s 秒 0 59 ?6Y?;dMillisecond Ms - 毫秒 0 999 AQ彩堐?E8?闪潽麘缂p彰t3access 和 asp 中用date()和now()取得系统日期时间;其中DateDiff,DateAdd,DatePart也同是能用于Access和asp中,这些函数的用法也类似畵?b?HLu 阏p缤举例:/0R符?氦?1.GetDate() 用于sql server :select GetDate()邊象4 面?Xg# $逹2.DateDiff(s,2005-07-20,2005-7-25 22:56:32)返回值为 514592 秒O 侠 札DateDiff(d,2005-07-20,2005-7-25 22:56:32)返回值为 5 天倮KiC伅嬟v 嶇嶽?觬3.DatePart(w,2005-7-25 22:56:32)返回值为 2 即星期一(周日为1,周六为7)?聕qV0?DatePart(d,2005-7-25 22:56:32)返回值为 25即25号y萱1雍破?DatePart(y,2005-7-25 22:56:32)返回值为 206即这一年中第206天髄? 驐?DatePart(yyyy,2005-7-25 22:56:32)返回值为 2005即2005年=MSSQL汉字转拼音函数实现语句2009-11-10 16:37/* -函数: fn_GetPinyin描述: 汉字转拼音(无数据表版)使用: dbo.fn_GetPinyin(中华人民共和国) = zhonghuarenmingongheguo作者: 流香羽 (改编:Tony)- */IF OBJECT_ID(fn_GetPinyin) IS NOT NULLDROP FUNCTION fn_GetPinyinGOcreate function dbo.fn_GetPinyin(words nvarchar(2000)returns varchar(8000)asbegindeclare word nchar(1)declare pinyin varchar(8000)declare i intdeclare words_len intdeclare unicode intset i = 1set words = ltrim(rtrim(words)set words_len = len(words)while (i = words_len) -循环取字符beginset word = substring(words, i, 1)set unicode = unicode(word)set pinyin = ISNULL(pinyin +SPACE(1),)+(case when unicode(word) between 19968 and 19968+20901 then(select top 1 py from (select a as py,N厑 as wordunion all select ai,N靉union all select an,N黯union all select ang,N醠union all select ao,N驁union all select ba,N欛union all select bai,N瓸 -韛兡瓸union all select ban,N瓣union all select bang,N鎊union all select bao,N鑤union all select bei,N鐾union all select ben,N輽union all select beng,N鏰union all select bi,N鼊union all select bian,N變union all select biao,N鰾union all select bie,N彆union all select bin,N鬢union all select bing,N靐union all select bo,N蔔union all select bu,N簿union all select ca,N囃union all select cai,N乲 -縩乲union all select can,N爘union all select cang,N賶union all select cao,N鼜union all select ce,N簎union all select cen,N笒union all select ceng,N乽 -硛硳岾猠乽union all select cha,N詫union all select chai,N囆union all select chan,N顫union all select chang,N韔union all select chao,N觘union all select che,N爡union all select chen,N讖union all select cheng,N秤union all select chi,N鷘union all select chong,N銃union all select chou,N殠union all select chu,N矗union all select chuai,N踹union all select chuan,N鶨union all select chuang,N愴union all select chui,N顀union all select chun,N蠢union all select chuo,N縒union all select ci,N嗭 -賜嗭union all select cong,N謥union all select cou,N輳union all select cu,N顣union all select cuan,N爨union all select cui,N臎union all select cun,N籿union all select cuo,N錯union all select da,N橽union all select dai,N靆union all select dan,N饏union all select dang,N闣union all select dao,N纛union all select de,N的union all select den,N扽union all select deng,N鐙union all select di,N螮union all select dia,N嗲union all select dian,N驔union all select diao,N鑃union all select die,N嚸 -眰嚸union all select ding,N顁union all select diu,N銩union all select dong,N霘union all select dou,N鬭union all select du,N蠹union all select duan,N叾 -籪叾union all select dui,N譵union all select dun,N踲union all select duo,N鵽union all select e,N鱷union all select en,N摁union all select eng,N鞥union all select er,N樲union all select fa,N髮union all select fan,N瀪union all select fang,N放union all select fei,N靅union all select fen,N鱝union all select feng,N覅union all select fo,N梻union all select fou,N鴀union all select fu,N猤 -鰒猤union all select ga,N魀union all select gai,N瓂union all select gan,N灨union all select gang,N戇union all select gao,N鋯union all select ge,N獦union all select gei,N給union all select gen,N搄union all select geng,N堩 -亙堩啹喼嗰union all select gong,N兣 -熕贑兝兣union all select gou,N購union all select gu,N顧union all select gua,N詿union all select guai,N恠union all select guan,N鱹union all select guang,N撗union all select gui,N鱥union all select gun,N謴union all select guo,N腂union all select ha,N哈union all select hai,N饚union all select han,N鶾union all select hang,N沆union all select hao,N兞union all select he,N靏union all select hei,N嬒union all select hen,N恨union all select heng,N堼 -堼囍union all select hong,N鬨union all select hou,N鱟union all select hu,N鸌union all select hua,N蘳union all select huai,N蘾union all select huan,N鰀union all select huang,N鎤union all select hui,N顪union all select hun,N諢union all select huo,N夻union all select ji,N驥union all select jia,N嗧union all select jian,N鑳union all select jiang,N謽union all select jiao,N釂union all select jie,N繲union all select jin,N齽union all select jing,N竸union all select jiong,N蘔union all select jiu,N欍union all select ju,N爠union all select juan,N羂union all select jue,N钁union all select jun,N攈union all select ka,N鉲union all select kai,N乫 -鎎乫union all select kan,N矙union all select kang,N閌union all select kao,N鯌union all select ke,N騍union all select ken,N褃union all select keng,N鏗 -巪乬唟厼怾union all select kong,N廤union all select kou,N鷇union all select ku,N嚳union all select kua,N骻union all select kuai,N鱠union all select kuan,N窾union all select kuang,N鑛union all select kui,N鑎union all select kun,N睏union all select kuo,N穒union all select la,N鞡union all select lai,N籟union all select lan,N糷union all select lang,N唥union all select lao,N軂union all select le,N餎union all select lei,N脷 -嘞脷union all select leng,N睖union all select li,N瓈union all select lia,N倆union all select lian,N纞union all select liang,N鍄union all select liao,N瞭union all select lie,N鱲union all select lin,N轥 -轥拎union all select ling,N炩union all select liu,N咯 -瓼甅囖咯union all select long,N贚union all select lou,N鏤union all select lu,N氇union all select lv,N鑢union all select luan,N亂union all select lue,N擽union all select lun,N論union all select luo,N鱳union all select ma,N嘛union all select mai,N霢union all select man,N蘰union all select mang,N蠎union all select mao,N唜union all select me,N癦 -癦呅union all select mei,N嚜union all select men,N們union all select meng,N霥 -霿踎union all select mi,N羃union all select mian,N麵union all select miao,N廟union all select mie,N鱴 -鱴瓱union all select min,N鰵union all select ming,N詺union all select miu,N謬union all select mo,N耱 -耱乮union all select mou,N麰 -麰蟱union all select mu,N旀union all select na,N魶union all select nai,N錼union all select nan,N婻union all select nang,N齉union all select nao,N臑union all select ne,N呢union all select nei,N焾 -嫩焾union all select nen,N嫩union all select neng,N能 -莻嗯鈪銰啱union all select ni,N嬺union all select nian,N艌union all select niang,N釀union all select niao,N脲union all select nie,N钀union all select nin,N拰union all select ning,N濘union all select niu,N靵union all select nong,N齈union all select nou,N譳union all select nu,N搙union all select nv,N衄union all select nue,N瘧union all select nuan,N燶 -硸黁燶郍union all select nuo,N桛union all select o,N鞰 -毮夞乯鞰union all select ou,N漚union all select pa,N袙union all select pai,N磗 -鎃磗union all select pan,N鑻union all select pang,N胖union all select pao,N礮union all select pei,N轡union all select pen,N喯union all select peng,N喸 -浌巼闏乶喸union all select pi,N鸊union all select pian,N騙union all select piao,N慓union all select pie,N嫳union all select pin,N聘union all select ping,N蘋union all select po,N魄union all select pou,N哛 -兺哛union all select pu,N曝union all select qi,N蟿union all select qia,N髂union all select qian,N縴union all select qiang,N瓩 -羻兛瓩union all select qiao,N躈union all select qie,N籡union all select qin,N藽union all select qing,N櫦union all select qiong,N瓗union all select qiu,N糗union all select qu,N覻union all select quan,N勸union all select que,N礭union all select qun,N囕union all select ran,N橪union all select rang,N讓union all select rao,N繞union all select re,N熱union all select ren,N餁union all select reng,N陾union all select ri,N馹union all select rong,N穃union all select rou,N嶿union all select ru,N擩union all select ruan,N礝union all select rui,N壡union all select run,N橍 -橍挼union all select ruo,N鶸union all select sa,N栍 -櫒栍union all select sai,N虄 -簺虄union all select san,N閐union all select sang,N喪union all select sao,N髞union all select se,N飋 -裇聓union all select sen,N篸union all select seng,N縇 -閪縇union all select sha,N霎union all select shai,N曬union all select shan,N鱔union all select shang,N緔union all select shao,N潲union all select she,N欇union all select shen,N瘮union all select sheng,N賸union all select shi,N瓧 -鰘齛兙瓧union all select shou,N鏉union all select shu,N虪union all select shua,N誜union all select shuai,N卛union all select shuan,N腨union all select shuang,N灀union all select shui,N睡union all select shun,N鬊union all select shuo,N鑠union all select si,N乺 -瀃螦乺union all select song,N鎹union all select sou,N瘶union all select su,N鷫union all select suan,N算union all select sui,N鐩union all select sun,N潠union all select suo,N蜶union all select ta,N襨 -躢襨union all select tai,N燤union all select tan,N賧union all select tang,N燙union all select tao,N畓 -討畓union all select te,N蟘union all select teng,N朰 -霯唞朰union all select ti,N趯union all select tian,N舚union all select tiao,N糶union all select tie,N餮union all select ting,N乭 -濎乭union all select tong,N憅union all select tou,N透union a

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论