Excel使用函数将公历日期转换为农历
“小狗逃跑计划”通过精心收集,向本站投稿了6篇Excel使用函数将公历日期转换为农历,今天小编在这给大家整理后的Excel使用函数将公历日期转换为农历,我们一起来看看吧!
篇1:Excel使用函数将公历日期转换为农历
①启动Excel,在任意一个单元格输入下列函数:“=TEXT(NOW,“[$-130000]YYYY-M-D”)”。
输入函数②该单元格立即得到一个日期,如下图所示,农历日期为六月初一。虽然在遇到闰月时,显示结果有点差强人意,如下图中,2月9日的农历应是十二月二十六,但因为那年有个闰五月,就无辜多出来一个月了,
不过总比编代码要快捷多了吧,而且闰月也不是天天有。
输入日期③如果想要完全以农历形式显示出来,那么可以输入下列公式:=MID(“ 甲乙丙丁戊己庚辛壬癸”,MOD(TEXT(NOW(),“[$-130000]e”)-4,10)+1,1)&MID(“子丑寅卯辰巳午未申酉 戌亥”,MOD(TEXT(NOW(),“[$-130000]e”)-4,12)+1,1)&“年”&TEXT(NOW(),“ [$-130000][DBNum1]m月d日”)
输入公式④对于公式各个参数的说明,大家如有疑问可以留言,我会跟大家解答。
篇2:使用函数将Excel中的日期转换为星期
生活中,我们的日期和星期是紧密联系在一起的,这是两种不同的计时方式,也是可以进行转换的,比如从日期到星期的转换,那么在Excel中我们能不能根据日期来显示出星期呢?要怎么做呢?
方法一:转换成英文的星期格式
用Excel2013打开一篇含有日期的工作表,如下图,我们在B2单元格中输入函数“=TEXT(WEEKDAY(A2),“dddd”)”,按下回车键,然后给需要的单元格进行自动填充。
方法二:转换成中文的星期格式我们在C2单元格中输入函数“=TEXT(WEEKDAY(A2),“aaaa”)”,然后按下回车键,也给需要的单元格使用自动填充功能,效果如下,
提示:大家可以根据自己的需要选择是得到英文的还是中文的星期格式。篇3:Excel使用MID函数将非日期数据转换成标准日期
方法/步骤
选择B2单元格,输入“=DATE(MID(A2,1,4),MID(A2,5,2),MID(A2,7,2))”,按回车,即可快速将A2单元格中的简易输入转换成标准日期格式,
Excel使用MID函数将非日期数据转换成标准日期
,
办公软件教程
选择B2单元格,复制填充至B3:B5,自动完成其他简易输入的转换。
篇4:DedeCMS将IP地址转换为纯真IP数据库的地区的实现函数
DedeCMS的后台可以查询发布文章和评论的IP地址,dedecms默认的IP地址库却不是现在最流行纯真IP数据库,那么如何将织梦cms的IP地址转换为纯真IP数据库的函数呢?
可以通过以下方法修改实现
实现方法
第一步:函数编写
在/include/extend.func.php文件中的?>的上面加入以下函数代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
+------------------------------------------------------------------------+
| 本代码来源于织梦教程网(xuewl.com)
+------------------------------------------------------------------------+
| Author : 华强Y (QQ:3421209)
| Email : master@xuewl.com
| WebSite: bbs.xuewl.com
| Contact: t.qq.com/dede_tech
| Copyright @ - 织梦教程网(xuewl.com)
+------------------------------------------------------------------------+
+ 不管是否为商业用途,您必须保留此头部信息并不得修改,尊重版权从现在做起 +
*/
functionconvertip($ip){
$dat_path=DEDEDATA.'/ip/QQWry.dat';
if(!ereg(“^([0-9]{1,3}.){3}[0-9]{1,3}$”,$ip)){
return'IP格式错误';
}
if(!$fd=@fopen($dat_path,'rb')){
return'无法打开IP数据库';
}
$ip=explode('.',$ip);
$ipNum=$ip[0]*16777216+$ip[1]*65536+$ip[2]*256+$ip[3];
$DataBegin=fread($fd,4);
$DataEnd=fread($fd,4);
$ipbegin=implode('',unpack('L',$DataBegin));
if($ipbegin<0)$ipbegin+=pow(2,32);
$ipend=implode('',unpack('L',$DataEnd));
if($ipend<0)$ipend+=pow(2,32);
$ipAllNum=($ipend-$ipbegin)/7+1;
$BeginNum=0;
$EndNum=$ipAllNum;
while($ip1num>$ipNum||$ip2num<$ipNum){
$Middle=intval(($EndNum+$BeginNum)/2);
fseek($fd,$ipbegin+7*$Middle);
$ipData1=fread($fd,4);
if(strlen($ipData1)<4){
fclose($fd);
return'System Error';
}
$ip1num=implode('',unpack('L',$ipData1));
if($ip1num<0)$ip1num+=pow(2,32);
if($ip1num>$ipNum){
$EndNum=$Middle;
continue;
}
$DataSeek=fread($fd,3);
if(strlen($DataSeek)<3){
fclose($fd);
return'System Error';
}
$DataSeek=implode('',unpack('L',$DataSeek.chr(0)));
fseek($fd,$DataSeek);
$ipData2=fread($fd,4);
if(strlen($ipData2)<4){
fclose($fd);
return'System Error';
}
$ip2num=implode('',unpack('L',$ipData2));
if($ip2num<0)$ip2num+=pow(2,32);
if($ip2num<$ipNum){
if($Middle==$BeginNum){
fclose($fd);
return'Unknown';
}
$BeginNum=$Middle;
}
}
$ipFlag=fread($fd,1);
if($ipFlag==chr(1)){
$ipSeek=fread($fd,3);
if(strlen($ipSeek)<3){
fclose($fd);
return'System Error';
}
$ipSeek=implode('',unpack('L',$ipSeek.chr(0)));
fseek($fd,$ipSeek);
$ipFlag=fread($fd,1);
}
if($ipFlag==chr(2)){
$AddrSeek=fread($fd,3);
if(strlen($AddrSeek)<3){
fclose($fd);
return'System Error';
}
$ipFlag=fread($fd,1);
if($ipFlag==chr(2)){
$AddrSeek2=fread($fd,3);
if(strlen($AddrSeek2)<3){
fclose($fd);
return'System Error';
}
$AddrSeek2=implode('',unpack('L',$AddrSeek2.chr(0)));
fseek($fd,$AddrSeek2);
}else{
fseek($fd,-1,SEEK_CUR);
}
while(($char=fread($fd,1))!=chr(0))
$ipAddr2.=$char;
$AddrSeek=implode('',unpack('L',$AddrSeek.chr(0)));
fseek($fd,$AddrSeek);
while(($char=fread($fd,1))!=chr(0))
$ipAddr1.=$char;
}else{
fseek($fd,-1,SEEK_CUR);
while(($char=fread($fd,1))!=chr(0))
$ipAddr1.=$char;
$ipFlag=fread($fd,1);
if($ipFlag==chr(2)){
$AddrSeek2=fread($fd,3);
if(strlen($AddrSeek2)<3){
fclose($fd);
return'System Error';
}
$AddrSeek2=implode('',unpack('L',$AddrSeek2.chr(0)));
fseek($fd,$AddrSeek2);
}else{
fseek($fd,-1,SEEK_CUR);
}
while(($char=fread($fd,1))!=chr(0)){
$ipAddr2.=$char;
}
}
fclose($fd);
//最后做相应的替换操作后返回结果
if(preg_match('/http/i',$ipAddr2)){
$ipAddr2='';
}
$ipaddr=“$ipAddr1$ipAddr2”;
$ipaddr=preg_replace('/CZ88.Net/is','',$ipaddr);
$ipaddr=preg_replace('/^s*/is','',$ipaddr);
$ipaddr=preg_replace('/s*$/is','',$ipaddr);
if(preg_match('/http/i',$ipaddr)||$ipaddr==''){
$ipaddr='Unknown';
}
return$ipaddr;
}
篇5:将小写金额转换为中文大写的SQL函数数据库教程
大写|函数|金额|小写|中文|转换
CREATE FUNCTION [dbo].[f_num_chn] (@num numeric(14,2))
RETURNS varchar(100) WITH ENCRYPTION
AS
BEGIN
--版权所有:pbsql
DECLARE @n_data VARCHAR(20),@c_data VARCHAR(100),@n_str VARCHAR(10),@i int
SET @n_data=RIGHT(SPACE(14)+CAST(CAST(ABS(@num*100) AS bigint) AS varchar(20)),14)
SET @c_data=''
SET @i=1
WHILE @i<=14
BEGIN
SET @n_str=SUBSTRING(@n_data,@i,1)
IF @n_str' '
BEGIN
IF not ((SUBSTRING(@n_data,@i,2)='00') or
((@n_str='0') and ((@i=4) or (@i=8) or (@i=12) or (@i=14))))
SET @c_data=@c_data+SUBSTRING('零壹贰叁肆伍陆柒捌玖',CAST(@n_str AS int)+1,1)
IF not ((@n_str='0') and (@i4) and (@i8) and (@i12))
SET @c_data=@c_data+SUBSTRING('仟佰拾亿仟佰拾万仟佰拾圆角分',@i,1)
IF SUBSTRING(@c_data,LEN(@c_data)-1,2)='亿万'
SET @c_data=SUBSTRING(@c_data,1,LEN(@c_data)-1)
END
SET @i=@i+1
END
IF @num<0
SET @c_data='(负数)'+@c_data
IF @num=0
SET @c_data='零圆'
IF @n_str='0'
SET @c_data=@c_data+'整'
RETURN(@c_data)
END
篇6:将小写金额转换为英文大写的SQL函数数据库教程
大写|函数|金额|小写|转换
CREATE FUNCTION [dbo].[f_num_eng] (@num numeric(15,2))RETURNS varchar(400) WITH ENCRYPTION
AS
BEGIN
--All rights reserved. pbsql
DECLARE @i int,@hundreds int,@tenth int,@one int
DECLARE @thousand int,@million int,@billion int
DECLARE @numbers varchar(400),@s varchar(15),@result varchar(400)
SET @numbers='one two three four five '
+'six seven eight nine ten '
+'eleven twelve thirteen fourteen fifteen '
+'sixteen seventeen eighteen nineteen '
+'twenty thirty forty fifty '
+'sixty seventy eighty ninety '
SET @s=RIGHT('000000000000000'+CAST(@num AS varchar(15)),15)
SET @billion=CAST(SUBSTRING(@s,1,3) AS int)--将12位整数分成4段:十亿、百万、千、百十个
SET @million=CAST(SUBSTRING(@s,4,3) AS int)
SET @thousand=CAST(SUBSTRING(@s,7,3) AS int)
SET @result=''
SET @i=0
WHILE @i<=3
BEGIN
SET @hundreds=CAST(SUBSTRING(@s,@i*3+1,1) AS int)--百位0-9
SET @tenth=CAST(SUBSTRING(@s,@i*3+2,1) AS int)
SET @one=(CASE @tenth WHEN 1 THEN 10 ELSE 0 END)+CAST(SUBSTRING(@s,@i*3+3,1) AS int)--个位0-19
SET @tenth=(CASE WHEN @tenth<=1 THEN 0 ELSE @tenth END)--十位0、2-9
IF (@i=1 and @billion>0 and (@million>0 or @thousand>0 or @hundreds>0)) or
(@i=2 and (@billion>0 or @million>0) and (@thousand>0 or @hundreds>0)) or
(@i=3 and (@billion>0 or @million>0 or @thousand>0) and (@hundreds>0))
SET @result=@result+', '--百位不是0则每段之间加连接符,
IF (@i=3 and (@billion>0 or @million>0 or @thousand>0) and (@hundreds=0 and (@tenth>0 or @one>0)))
SET @result=@result+' and '--百位是0则加连接符AND
IF @hundreds>0
SET @result=@result+RTRIM(SUBSTRING(@numbers,@hundreds*10-9,10))+' hundred'
IF @tenth>=2 and @tenth<=9
BEGIN
IF @hundreds>0
SET @result=@result+' and '
SET @result=@result+RTRIM(SUBSTRING(@numbers,@tenth*10+171,10))
END
IF @one>=1 and @one<=19
BEGIN
IF @tenth>0
SET @result=@result+'-'
ELSE
IF @hundreds>0
SET @result=@result+' and '
SET @result=@result+RTRIM(SUBSTRING(@numbers,@one*10-9,10))
END
IF @i=0 and @billion>0
SET @result=@result+' billion'
IF @i=1 and @million>0
SET @result=@result+' million'
IF @i=2 and @thousand>0
SET @result=@result+' thousand'
SET @i=@i+1
END
IF SUBSTRING(@s,14,2)'00'
BEGIN
SET @result=@result+' point '
IF SUBSTRING(@s,14,1)='0'
SET @result=@result+'zero'
ELSE
SET @result=@result+RTRIM(SUBSTRING(@numbers,CAST(SUBSTRING(@s,14,1) AS int)*10-9,10))
IF SUBSTRING(@s,15,1)'0'
SET @result=@result+' '+RTRIM(SUBSTRING(@numbers,CAST(SUBSTRING(@s,15,1) AS int)*10-9,10))
END
RETURN(@result)
END
【Excel使用函数将公历日期转换为农历】相关文章:






文档为doc格式